from pathlib import Path
from typing import Optional
from pydantic_settings import BaseSettings


class Settings(BaseSettings):
    # Database
    database_url: str = "postgresql+asyncpg://animequiz:animequiz123@localhost:5432/animequiz"

    # S3 Storage settings
    s3_endpoint: str = "https://s3.firstvds.ru"
    s3_access_key: str = ""
    s3_secret_key: str = ""
    s3_region: str = "default"
    s3_bucket: str = "anime-quiz"

    # Local paths
    output_path: Path = Path("/app/output/videos")
    temp_path: Path = Path("/tmp/anime_quiz")
    cache_path: Path = Path("/tmp/anime_quiz/cache")

    # Video settings
    shorts_width: int = 1080
    shorts_height: int = 1920
    full_width: int = 1920
    full_height: int = 1080

    # Timing settings (seconds)
    answer_duration: float = 5.0
    final_screen_duration: float = 3.0
    audio_buffer: float = 1.0

    # Audio
    audio_fade_duration: float = 0.7

    class Config:
        env_file = ".env"
        env_file_encoding = "utf-8"
        extra = "ignore"


settings = Settings()

# Ensure directories exist
settings.temp_path.mkdir(parents=True, exist_ok=True)
settings.output_path.mkdir(parents=True, exist_ok=True)
settings.cache_path.mkdir(parents=True, exist_ok=True)
