"""
mizan Settings

Configuration is read from Django settings with sensible defaults.
"""

from dataclasses import dataclass
from functools import lru_cache

from django.conf import settings as django_settings


@dataclass
class mizanSettings:
    """mizan configuration."""

    # Cache HMAC signing secret (required when cache is enabled)
    cache_secret: str | None

    # Redis URL for cache backend (None = cache disabled)
    cache_redis_url: str | None

    # MWT signing secret (separate from cache secret for blast radius containment)
    mwt_secret: str | None

    # MWT token lifetime in seconds (default: 300 = 5 minutes)
    mwt_ttl: int


@lru_cache
def get_settings() -> mizanSettings:
    """
    Load mizan settings from Django settings.

    Settings:
        MIZAN_CACHE_SECRET: HMAC signing key for cache keys (default: None)
        MIZAN_CACHE_REDIS_URL: Redis connection URL (default: None)
    """
    return mizanSettings(
        cache_secret=getattr(django_settings, "MIZAN_CACHE_SECRET", None),
        cache_redis_url=getattr(django_settings, "MIZAN_CACHE_REDIS_URL", None),
        mwt_secret=getattr(django_settings, "MIZAN_MWT_SECRET", None),
        mwt_ttl=getattr(django_settings, "MIZAN_MWT_TTL", 300),
    )


def clear_settings_cache():
    """Clear the settings cache (for testing)."""
    get_settings.cache_clear()
