"""Tests for agntor.client — SDK client initialization and error handling."""

import pytest
from agntor import Agntor
from agntor.types import AgntorError


class TestClientInit:
    def test_valid_init(self):
        client = Agntor(api_key="test_key", agent_id="agent-1", chain="base")
        assert client._api_key == "test_key"
        assert client._agent_id == "agent-1"
        assert client._chain == "base"

    def test_missing_api_key(self):
        with pytest.raises(AgntorError, match="api_key is required"):
            Agntor(api_key="", agent_id="agent-1", chain="base")

    def test_missing_agent_id(self):
        with pytest.raises(AgntorError, match="agent_id is required"):
            Agntor(api_key="test_key", agent_id="", chain="base")

    def test_custom_base_url(self):
        client = Agntor(
            api_key="test_key",
            agent_id="agent-1",
            chain="base",
            base_url="https://custom.example.com/",
        )
        assert client._base_url == "https://custom.example.com"  # trailing slash stripped

    def test_default_values(self):
        client = Agntor(api_key="k", agent_id="a", chain="base")
        assert client._base_url == "https://app.agntor.com"
        assert client._timeout == 30.0
        assert client._max_retries == 3

    def test_submodules_exist(self):
        client = Agntor(api_key="k", agent_id="a", chain="base")
        assert hasattr(client, "identity")
        assert hasattr(client, "trust")
        assert hasattr(client, "escrow")
        assert hasattr(client, "settle")
        assert hasattr(client, "audit")
        assert hasattr(client, "health")
