from pydantic_settings import BaseSettings
from functools import lru_cache


class Settings(BaseSettings):
    """Application settings loaded from environment variables."""

    # Audiobookshelf Configuration (Optional - for backward compatibility)
    # In multi-user mode, each user provides their own credentials
    abs_url: str | None = None
    abs_api_token: str | None = None

    # AI Configuration
    gemini_api_key: str | None = None
    anthropic_api_key: str | None = None
    openai_api_key: str | None = None

    # Application Configuration
    database_url: str = "sqlite:///./absrecommend.db"
    secret_key: str = "change-me-in-production-please-use-a-strong-random-key"
    host: str = "0.0.0.0"
    port: int = 8000

    class Config:
        env_file = ".env"
        case_sensitive = False


@lru_cache()
def get_settings() -> Settings:
    """Get cached settings instance."""
    return Settings()
