from pathlib import Path
from pydantic_settings import BaseSettings


class Settings(BaseSettings):
    """Application configuration loaded from environment variables."""

    host: str = "0.0.0.0"
    port: int = 8765
    log_level: str = "INFO"

    # TTS model configuration
    tts_backend: str = "f5_tts"  # or "dummy" for tests
    tts_model_name: str = "F5TTS_v1_Base"  # env: TTS_MODEL_NAME
    tts_model_path: Path | None = None
    tts_vocab_path: Path | None = None
    tts_sample_rate: int = 24_000

    # Reference voices directory
    voices_dir: Path = Path("voices")

    # Segmentation thresholds
    min_segment_length: int = 30
    max_segment_length: int = 200
    max_buffer_wait_ms: int = 500

    # GPU / inference
    device: str = "cuda"  # or "cpu"
    dtype: str = "bfloat16"

    # Voice reference
    default_voice_ref: Path | None = None  # env: DEFAULT_VOICE_REF
    default_ref_text: str | None = None  # env: DEFAULT_REF_TEXT

    # Warm-up
    warmup: bool = False  # run a dummy inference at startup
    warmup_text: str = "Привет. Это тестовая фраза."

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


settings = Settings()
