"""
ABOS AI Worker – Application Configuration
==========================================
Centralised settings loaded from environment variables via Pydantic BaseSettings.
No secrets are hard-coded here; all sensitive values must be supplied at runtime
by the Spring Boot orchestrator or via a local .env file for development.
"""

from pydantic_settings import BaseSettings, SettingsConfigDict


class Settings(BaseSettings):
    model_config = SettingsConfigDict(
        env_file=".env",
        env_file_encoding="utf-8",
        extra="ignore",
    )

    # ---------------------------------------------------------------------------
    # Service identity
    # ---------------------------------------------------------------------------
    app_name: str = "ABOS AI Worker"
    app_version: str = "1.0.0"
    debug: bool = False

    # ---------------------------------------------------------------------------
    # CORS – origins allowed to call the frontend-facing endpoints.
    # In production, restrict this to your React app's actual origin.
    # ---------------------------------------------------------------------------
    cors_origins: list[str] = [
        "http://localhost:3000",
        "http://localhost:5173",
        "http://localhost:5174",
    ]

    # ---------------------------------------------------------------------------
    # Transient storage
    # ---------------------------------------------------------------------------
    # Maximum seconds to keep a document in memory before it is evicted.
    document_ttl_seconds: int = 3600  # 1 hour

    # ---------------------------------------------------------------------------
    # OpenRouter defaults
    # ---------------------------------------------------------------------------
    # The preferred model to use.  Spring Boot may override per-request.
    openrouter_default_model: str = "openai/gpt-oss-20b:free"
    openrouter_base_url: str = "https://openrouter.ai/api/v1"

    # Layered-extraction fallback chain: tried in order, after the primary model, ONLY for
    # fields still null/missing. Each entry must differ from the primary model actually used.
    openrouter_fallback_models: list[str] = [
        "google/gemini-2.0-flash-exp:free",
        "meta-llama/llama-3.1-8b-instruct:free",
    ]

    # ---------------------------------------------------------------------------
    # HTTP client timeouts (seconds)
    # ---------------------------------------------------------------------------
    openrouter_timeout: int = 120
    webhook_timeout: int = 30


settings = Settings()
