"""Configuration management using Pydantic Settings."""

from pydantic import Field
from pydantic_settings import BaseSettings, SettingsConfigDict


class ChatMaskSettings(BaseSettings):
    """
    Type-safe configuration for AT Chat Mask.

    All settings can be configured via:
    1. Environment variables (e.g., ASKTABLE_API_KEY)
    2. .env file
    3. Direct instantiation
    """

    model_config = SettingsConfigDict(
        env_file=".env",
        env_file_encoding="utf-8",
        case_sensitive=False,
        extra="ignore",  # Ignore extra fields
    )

    # AskTable API Configuration
    asktable_api_key: str = Field(
        ...,
        description="AskTable API key for authentication",
    )

    asktable_api_base: str = Field(
        default="https://api.asktable.com",
        description="AskTable API base URL",
    )

    # LLM API Configuration
    llm_base_url: str = Field(
        default="https://aiproxy.dminfra.cn/v1",
        description="LLM API base URL",
    )

    llm_api_key: str = Field(
        default="",
        description="LLM API key for authentication",
    )

    llm_sql_model: str = Field(
        default="qwen3-max",
        description="LLM model for SQL field extraction (Qwen 3-Max)",
    )

    llm_data_gen_model: str = Field(
        default="qwen-turbo",
        description="LLM model for data generation (Qwen Turbo)",
    )

    # Data Generation Settings
    default_num_rows: int = Field(
        default=20,
        ge=1,
        le=1000,
        description="Default number of rows to generate in CSV",
    )

    max_sample_questions: int = Field(
        default=10,
        ge=1,
        le=50,
        description="Maximum number of sample questions to include in bot",
    )

    # Logging Settings
    log_level: str = Field(
        default="INFO",
        description="Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)",
    )

    log_file: str = Field(
        default="at_chat_mask.log",
        description="Path to log file",
    )

    # Datasource Wait Settings
    datasource_wait_timeout: int = Field(
        default=180,
        ge=10,
        le=300,
        description="Maximum seconds to wait for datasource to be ready",
    )

    datasource_wait_interval: int = Field(
        default=10,
        ge=1,
        le=30,
        description="Seconds between datasource status checks",
    )
