"""Tests for Agent Status SDK client."""

import pytest
from unittest.mock import Mock, patch

import agent_status
from agent_status.client import AgentStatusClient, AgentStatusError, AgentStatusAuthError, AgentStatusNotFoundError


class TestAgentStatusInit:
    def test_init_not_called(self):
        agent_status._client = None

        with pytest.raises(RuntimeError, match="not initialized"):
            agent_status.status("123")

    def test_init_success(self):
        agent_status.init(api_key="test_key")
        assert agent_status._client is not None
        assert agent_status._client.api_key == "test_key"


class TestAgentStatusClient:
    def test_client_creation(self):
        client = AgentStatusClient(api_key="test", base_url="https://example.com")
        assert client.api_key == "test"
        assert client.base_url == "https://example.com"

    def test_client_strips_trailing_slash(self):
        client = AgentStatusClient(api_key="test", base_url="https://example.com/")
        assert client.base_url == "https://example.com"


class TestErrors:
    def test_agent_status_error(self):
        error = AgentStatusError("Test error", status_code=500)
        assert str(error) == "Test error"
        assert error.status_code == 500

    def test_auth_error(self):
        error = AgentStatusAuthError("Invalid key", status_code=401)
        assert isinstance(error, AgentStatusError)
        assert error.status_code == 401

    def test_not_found_error(self):
        error = AgentStatusNotFoundError("Not found", status_code=404)
        assert isinstance(error, AgentStatusError)

    def test_backward_compat_aliases(self):
        from agent_status.client import RoraError, RoraAuthError, RoraNotFoundError, RoraClient
        assert RoraError is AgentStatusError
        assert RoraAuthError is AgentStatusAuthError
        assert RoraNotFoundError is AgentStatusNotFoundError
        assert RoraClient is AgentStatusClient
