"""SDK configuration."""

from pydantic import Field
from pydantic_settings import BaseSettings, SettingsConfigDict


class FishinfoConfig(BaseSettings):
    """Configuration for the Fishinfo SDK (Query-Only).

    This SDK is for querying fishinfo data only. For data ingestion,
    use the ingress-edge SDK instead.

    Configuration can be provided via:
    1. Constructor arguments
    2. Environment variables (FISHINFO_*)
    3. .env file

    Attributes:
        base_url: Base URL of the fishinfo API (e.g., https://fishinfo.example.com)
        api_key: API key for authentication (vk_live_... or vk_test_...)
        timeout: Default timeout for HTTP requests in seconds (default: 30)
        max_retries: Maximum number of retries for failed requests (default: 3)
        retry_delay: Initial retry delay in seconds (default: 1.0)
        retry_backoff: Backoff multiplier for retries (default: 2.0)
    """

    model_config = SettingsConfigDict(
        env_prefix="FISHINFO_",
        env_file=".env",
        env_file_encoding="utf-8",
        case_sensitive=False,
        extra="ignore",
    )

    # API configuration
    base_url: str = Field(
        ...,
        description="Base URL of the fishinfo API",
    )
    api_key: str = Field(
        ...,
        description="API key for authentication",
    )

    # HTTP configuration
    timeout: float = Field(
        default=30.0,
        gt=0,
        description="Default timeout for HTTP requests in seconds",
    )

    # Retry configuration
    max_retries: int = Field(
        default=3,
        ge=0,
        description="Maximum number of retries for failed requests",
    )
    retry_delay: float = Field(
        default=1.0,
        gt=0,
        description="Initial retry delay in seconds",
    )
    retry_backoff: float = Field(
        default=2.0,
        gt=1,
        description="Backoff multiplier for retries",
    )

    def is_test_mode(self) -> bool:
        """Check if using test API key.

        Returns:
            True if API key is a test key
        """
        return self.api_key.startswith("vk_test_")

    def is_live_mode(self) -> bool:
        """Check if using live API key.

        Returns:
            True if API key is a live key
        """
        return self.api_key.startswith("vk_live_")
