"""
config.py
All environment variables loaded once at startup.
Copy .env.example to .env and fill in your values before running.
"""
from pydantic_settings import BaseSettings
from functools import lru_cache


class Settings(BaseSettings):
    # ── App ──────────────────────────────────────────────────────────────────
    APP_NAME: str = "TranscriptIQ"
    APP_VERSION: str = "1.0.0"
    DEBUG: bool = False

    # ── Database (PostgreSQL on DGX) ─────────────────────────────────────────
    DATABASE_URL: str = "postgresql://transcriptiq:password@localhost:5432/transcriptiq_db"

    # ── Redis (Celery broker on DGX) ─────────────────────────────────────────
    REDIS_URL: str = "redis://localhost:6379/0"

    # ── Ollama (LLM on DGX) ──────────────────────────────────────────────────
    OLLAMA_BASE_URL: str = "http://localhost:11434"
    OLLAMA_MODEL: str = "llama3.3"

    # ── File storage (local DGX path) ────────────────────────────────────────
    STORAGE_BASE_PATH: str = "/data/transcriptiq/uploads"

    # ── JWT Auth ─────────────────────────────────────────────────────────────
    SECRET_KEY: str = "change-this-to-a-long-random-string-in-production"
    ALGORITHM: str = "HS256"
    ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24  # 24 hours

    # ── Stripe ───────────────────────────────────────────────────────────────
    STRIPE_SECRET_KEY: str = ""
    STRIPE_WEBHOOK_SECRET: str = ""
    STRIPE_STARTER_PRICE_ID: str = ""
    STRIPE_PRO_PRICE_ID: str = ""

    # ── CORS (Bluehost frontend domain) ──────────────────────────────────────
    CORS_ORIGINS: list[str] = [
        "https://transcriptiq.instituteofanalytics.com",
        "http://localhost:5173",  # Vite dev server
    ]

    # ── Plan limits ──────────────────────────────────────────────────────────
    STARTER_TRANSCRIPT_LIMIT: int = 50
    STARTER_PROJECT_LIMIT: int = 3
    PRO_TRANSCRIPT_LIMIT: int = 999999  # effectively unlimited

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


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


settings = get_settings()
