"""
Tests for account API.
"""

from unittest.mock import patch

import pytest

from getbiji_box import GetBijiClient
from getbiji_box.models import User


class TestAccountAPI:
    """Test cases for AccountAPI class."""

    @patch("getbiji_box.client.GetBijiClient.get")
    def test_get_info(self, mock_get):
        """Test getting user info."""
        mock_get.return_value = {
            "h": {"c": 0},
            "c": {
                "data": {
                    "uid": 12345,
                    "cellphone": "13800138000",
                    "nickname": "TestUser",
                    "avatar": "https://example.com/avatar.jpg",
                    "status": 1,
                    "vip_info": {"is_vip": True, "surplus_days": 30},
                    "rights_info": {"audio_duration_ms": 3600000},
                    "quota_info": {"local_audio_quota": {"remained_duration": 1800000}},
                    "labs": {"can_create_topics": True},
                    "create_time": 1609459200,
                }
            },
        }

        client = GetBijiClient(token="test_token")
        user = client.account.get_info()

        assert user.uid == 12345
        assert user.nickname == "TestUser"
        assert user.is_vip is True
        assert user.surplus_days == 30

    @patch("getbiji_box.client.GetBijiClient.get")
    def test_is_vip(self, mock_get):
        """Test is_vip convenience method."""
        mock_get.return_value = {
            "h": {"c": 0},
            "c": {
                "data": {
                    "uid": 1,
                    "cellphone": "",
                    "nickname": "U",
                    "avatar": "",
                    "status": 1,
                    "vip_info": {"is_vip": True, "surplus_days": 10},
                    "rights_info": {"audio_duration_ms": 0},
                    "quota_info": {"local_audio_quota": {"remained_duration": 0}},
                    "labs": {"can_create_topics": False},
                    "create_time": 0,
                }
            },
        }

        client = GetBijiClient(token="test_token")
        assert client.account.is_vip() is True

    @patch("getbiji_box.client.GetBijiClient.get")
    def test_get_remaining_audio_quota(self, mock_get):
        """Test getting remaining audio quota."""
        mock_get.return_value = {
            "h": {"c": 0},
            "c": {
                "data": {
                    "uid": 1,
                    "cellphone": "",
                    "nickname": "U",
                    "avatar": "",
                    "status": 1,
                    "vip_info": {"is_vip": False, "surplus_days": 0},
                    "rights_info": {"audio_duration_ms": 3600000},
                    "quota_info": {"local_audio_quota": {"remained_duration": 1800000}},
                    "labs": {"can_create_topics": False},
                    "create_time": 0,
                }
            },
        }

        client = GetBijiClient(token="test_token")
        quota = client.account.get_remaining_audio_quota()
        assert quota == 1800000

    @patch("getbiji_box.client.GetBijiClient.get")
    def test_can_create_knowledge_bases(self, mock_get):
        """Test can_create_knowledge_bases convenience method."""
        mock_get.return_value = {
            "h": {"c": 0},
            "c": {
                "data": {
                    "uid": 1,
                    "cellphone": "",
                    "nickname": "U",
                    "avatar": "",
                    "status": 1,
                    "vip_info": {"is_vip": False, "surplus_days": 0},
                    "rights_info": {"audio_duration_ms": 0},
                    "quota_info": {"local_audio_quota": {"remained_duration": 0}},
                    "labs": {"can_create_topics": True},
                    "create_time": 0,
                }
            },
        }

        client = GetBijiClient(token="test_token")
        assert client.account.can_create_knowledge_bases() is True


if __name__ == "__main__":
    pytest.main([__file__, "-v"])
