"""Tests for the main SedSH client."""

import pytest
from sed_sh import SedSH


class TestSedSHClient:
    """Test suite for SedSH client."""

    def test_client_initialization_with_api_key(self, api_key):
        """Test client initializes with API key."""
        client = SedSH(api_key=api_key)
        assert client.api_key == api_key
        assert client.links is not None
        assert client.malware is not None
        assert client.inbox is not None
        assert client.routes is not None
        assert client.reports is not None

    def test_client_initialization_with_env_var(self, monkeypatch):
        """Test client initializes with environment variable."""
        test_key = "env_api_key_67890"
        monkeypatch.setenv("SEDSH_API_KEY", test_key)
        client = SedSH()
        assert client.api_key == test_key

    def test_client_initialization_without_api_key(self, monkeypatch):
        """Test client raises error without API key."""
        monkeypatch.delenv("SEDSH_API_KEY", raising=False)
        with pytest.raises(ValueError, match="API key not found"):
            SedSH()

    def test_client_context_manager(self, api_key):
        """Test client works as context manager."""
        with SedSH(api_key=api_key) as client:
            assert client.api_key == api_key

    def test_client_custom_base_url(self, api_key):
        """Test client accepts custom base URL."""
        custom_url = "https://custom-api.sed.sh"
        client = SedSH(api_key=api_key, base_url=custom_url)
        assert client.base_url == custom_url

    def test_client_services_initialized(self, api_key):
        """Test all services are initialized."""
        client = SedSH(api_key=api_key)
        assert hasattr(client, 'links')
        assert hasattr(client, 'malware')
        assert hasattr(client, 'inbox')
        assert hasattr(client, 'routes')
        assert hasattr(client, 'reports')
