"""Tests for SDK configuration."""

import pytest

from fishinfo.config import FishinfoConfig


class TestFishinfoConfig:
    """Tests for FishinfoConfig."""

    def test_basic_config(self):
        """Test basic configuration."""
        config = FishinfoConfig(
            base_url="https://fishinfo.example.com",
            api_key="vk_live_test123",
        )

        assert config.base_url == "https://fishinfo.example.com"
        assert config.api_key == "vk_live_test123"
        assert config.grpc_port == 50051
        assert config.timeout == 30.0

    def test_grpc_host_derivation(self):
        """Test gRPC host derivation from base_url."""
        config = FishinfoConfig(
            base_url="https://fishinfo.example.com",
            api_key="vk_test_123",
        )

        assert config.get_grpc_host() == "fishinfo.example.com"
        assert config.get_grpc_address() == "fishinfo.example.com:50051"

    def test_grpc_host_explicit(self):
        """Test explicit gRPC host configuration."""
        config = FishinfoConfig(
            base_url="https://fishinfo.example.com",
            api_key="vk_test_123",
            grpc_host="grpc.fishinfo.example.com",
            grpc_port=9090,
        )

        assert config.get_grpc_host() == "grpc.fishinfo.example.com"
        assert config.get_grpc_address() == "grpc.fishinfo.example.com:9090"

    def test_api_key_mode_detection(self):
        """Test API key mode detection."""
        live_config = FishinfoConfig(
            base_url="https://fishinfo.example.com",
            api_key="vk_live_test123",
        )
        assert live_config.is_live_mode()
        assert not live_config.is_test_mode()

        test_config = FishinfoConfig(
            base_url="https://fishinfo.example.com",
            api_key="vk_test_test123",
        )
        assert test_config.is_test_mode()
        assert not test_config.is_live_mode()

    def test_custom_timeouts(self):
        """Test custom timeout configuration."""
        config = FishinfoConfig(
            base_url="https://fishinfo.example.com",
            api_key="vk_test_123",
            timeout=60.0,
            grpc_timeout=120.0,
        )

        assert config.timeout == 60.0
        assert config.grpc_timeout == 120.0

    def test_retry_configuration(self):
        """Test retry configuration."""
        config = FishinfoConfig(
            base_url="https://fishinfo.example.com",
            api_key="vk_test_123",
            max_retries=5,
            retry_delay=2.0,
            retry_backoff=3.0,
        )

        assert config.max_retries == 5
        assert config.retry_delay == 2.0
        assert config.retry_backoff == 3.0

    def test_buffer_configuration(self):
        """Test buffer configuration."""
        config = FishinfoConfig(
            base_url="https://fishinfo.example.com",
            api_key="vk_test_123",
            buffer_size=20000,
            batch_size=200,
            batch_timeout=10.0,
        )

        assert config.buffer_size == 20000
        assert config.batch_size == 200
        assert config.batch_timeout == 10.0

    def test_transport_configuration(self):
        """Test transport configuration."""
        config = FishinfoConfig(
            base_url="https://fishinfo.example.com",
            api_key="vk_test_123",
            transport="grpc",
        )

        assert config.transport == "grpc"

    def test_mtls_configuration(self):
        """Test mTLS configuration."""
        config = FishinfoConfig(
            base_url="https://fishinfo.example.com",
            api_key="vk_test_123",
            grpc_tls=True,
            grpc_mtls_cert="/path/to/cert.pem",
            grpc_mtls_key="/path/to/key.pem",
            grpc_ca_cert="/path/to/ca.pem",
        )

        assert config.grpc_tls is True
        assert config.grpc_mtls_cert == "/path/to/cert.pem"
        assert config.grpc_mtls_key == "/path/to/key.pem"
        assert config.grpc_ca_cert == "/path/to/ca.pem"
