"""
Application Configuration
"""

from functools import lru_cache
from pydantic_settings import BaseSettings
from pydantic import Field


class Settings(BaseSettings):
    """Application settings"""

    # App
    APP_NAME: str = "YG-Dataset"
    DEBUG: bool = True
    HOST: str = "0.0.0.0"
    PORT: int = 8000

    # Database - 使用 SQLite 进行开发/测试
    # 生产环境可切换为 PostgreSQL
    DATABASE_URL: str = Field(
        default="sqlite:///./ygdataset.db",
        description="Database connection URL (sqlite:// or postgresql+asyncpg://)"
    )
    DATABASE_URL_SYNC: str = Field(
        default="sqlite:///./ygdataset.db",
        description="Synchronous database connection URL"
    )

    # Redis
    REDIS_URL: str = "redis://localhost:6379/0"

    # File Storage
    UPLOAD_DIR: str = "./uploads"
    MAX_FILE_SIZE: int = 100 * 1024 * 1024  # 100MB

    # LLM Settings
    DEFAULT_MODEL_PROVIDER: str = "openai"
    DEFAULT_MODEL_NAME: str = "gpt-4o-mini"

    class Config:
        env_file = ".env"
        extra = "allow"


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