from pydantic_settings import BaseSettings
from functools import lru_cache


class Settings(BaseSettings):
    # Database
    database_url: str = "postgresql+asyncpg://dwa_user:dwa_pass@localhost:5437/dwa_ai_tracker"

    # Auth
    jwt_secret_key: str = "change-me-in-production"
    jwt_algorithm: str = "HS256"
    jwt_expiration_minutes: int = 1440

    # App
    app_env: str = "development"
    cors_origins: str = "http://localhost:3700"
    api_prefix: str = "/api"
    base_url: str = "http://localhost:8003"

    # Microsoft Graph (single app reg covers Copilot, Purview, Viva, SharePoint, Teams)
    graph_tenant_id: str | None = None
    graph_client_id: str | None = None
    graph_client_secret: str | None = None

    # Udemy Business
    udemy_base_url: str | None = None
    udemy_client_id: str | None = None
    udemy_client_secret: str | None = None
    udemy_account_id: str | None = None

    # LinkedIn Learning
    linkedin_client_id: str | None = None
    linkedin_client_secret: str | None = None

    # GitHub Copilot
    github_org: str | None = None
    github_token: str | None = None

    # Future: Azure AD SSO
    azure_ad_tenant_id: str | None = None
    azure_ad_client_id: str | None = None
    azure_ad_client_secret: str | None = None

    # Future: Teams
    teams_webhook_url: str | None = None

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


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