from pydantic_settings import BaseSettings
from functools import lru_cache


class Settings(BaseSettings):
    # API Keys
    OPENAI_API_KEY: str = ""
    PIXABAY_API_KEY: str = ""  # Optional: for Pixabay music search
    FREESOUND_API_KEY: str = ""  # Optional: for Freesound API (https://freesound.org/apiv2/apply)

    # Directories
    DOWNLOAD_DIR: str = "data/downloads"
    PROCESSED_DIR: str = "data/processed"
    BGM_DIR: str = "data/bgm"

    # Whisper settings
    WHISPER_MODEL: str = "medium"  # small, medium, large

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

    # OpenAI settings
    OPENAI_MODEL: str = "gpt-4o-mini"  # gpt-4o-mini, gpt-4o, gpt-4-turbo
    TRANSLATION_MAX_TOKENS: int = 1000  # Max tokens for translation (cost control)
    TRANSLATION_MODE: str = "rewrite"  # direct, summarize, rewrite

    # GPT Prompt Customization
    GPT_ROLE: str = "친근한 유튜브 쇼츠 자막 작가"  # GPT persona/role
    GPT_TONE: str = "존댓말"  # 존댓말, 반말, 격식체
    GPT_STYLE: str = ""  # Additional style instructions (optional)

    # Processing
    DEFAULT_FONT_SIZE: int = 24
    DEFAULT_FONT_COLOR: str = "white"
    DEFAULT_BGM_VOLUME: float = 0.3

    # Server
    PORT: int = 3000  # Frontend port

    # Proxy (for geo-restricted platforms like Douyin)
    PROXY_URL: str = ""  # http://host:port or socks5://host:port

    class Config:
        env_file = "../.env"  # Project root .env file
        extra = "ignore"  # Ignore extra fields in .env


@lru_cache()
def get_settings():
    return Settings()


settings = get_settings()
