from pydantic_settings import BaseSettings, SettingsConfigDict  # type: ignore
from functools import lru_cache
from pathlib import Path

_ENV_FILE = str(Path(__file__).parent / ".env")


class Settings(BaseSettings):
    mongodb_uri: str = "mongodb://localhost:27017"
    mongodb_db_name: str = "grateful_journal"
    api_port: int = 8001
    environment: str = "development"
    frontend_url: str = "http://localhost:8000"
    # Firebase Admin SDK service account JSON (paste the full JSON as a single-line string)
    firebase_service_account_json: str = ""

    model_config = SettingsConfigDict(
        env_file=_ENV_FILE,
        case_sensitive=False,
        extra="ignore",  # ignore unknown env vars (e.g. VITE_* from root .env)
    )


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