import os
from pydantic_settings import BaseSettings
from typing import Optional

class Settings(BaseSettings):
    APP_NAME: str = "Transcription Engine"
    VERSION: str = "0.1.0"
    DATABASE_URL: str = "sqlite:////app/transcripts.db"
    UPLOAD_DIR: str = "/app/uploads_audio"
    GEMINI_API_KEY: Optional[str] = None
    CHUNK_DURATION_SEC: int = 1800  # 30 Minutes

    class Config:
        env_file = ".env"

settings = Settings()

# Auto-load API Key
if not settings.GEMINI_API_KEY:
    key_path = "/app/gemini_api_key.txt"
    if os.path.exists(key_path):
        with open(key_path, "r") as f:
            settings.GEMINI_API_KEY = f.read().strip()

# Ensure Upload Dir exists
os.makedirs(settings.UPLOAD_DIR, exist_ok=True)
os.makedirs(os.path.join(settings.UPLOAD_DIR, "chunks"), exist_ok=True)
