from functools import lru_cache
from pathlib import Path

from pydantic import Field
from pydantic_settings import BaseSettings, SettingsConfigDict


class Settings(BaseSettings):
    model_config = SettingsConfigDict(env_file=".env", env_prefix="AUTOSHORTS_", extra="ignore")

    app_name: str = "AutoShorts Dashboard"
    environment: str = "local"
    app_base_url: str = "http://localhost:5173"
    public_app_url: str | None = None
    database_url: str = "sqlite:///./autoshorts_dashboard.db"
    redis_url: str = Field(default_factory=lambda: "redis" + "://redis:6379/0")
    storage_root: Path = Field(default_factory=lambda: Path("../storage"))
    secret_key: str = "change-me-in-production"
    max_upload_size_mb: int = 512
    cors_origins: list[str] = Field(default_factory=lambda: ["http://localhost:5173"])
    tiktok_sandbox: bool = True
    tiktok_client_id: str | None = None
    tiktok_client_secret: str | None = None
    google_client_id: str | None = None
    google_client_secret: str | None = None
    google_redirect_uri: str | None = None
    youtube_oauth_scope: str = "https://www.googleapis.com/auth/youtube.upload"
    youtube_default_privacy: str = "private"
    youtube_upload_notify_subscribers: bool = False
    youtube_default_category_id: str = "22"
    youtube_contains_synthetic_media_default: bool = True
    youtube_upload_dry_run: bool = False


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