"""Settings loaders with caching."""

from functools import lru_cache

from noteflow.config.settings._calendar import CalendarIntegrationSettings
from noteflow.config.settings._features import FeatureFlags
from noteflow.config.settings._main import Settings
from noteflow.config.settings._triggers import TriggerSettings


def _load_settings() -> Settings:
    """Load settings from environment.

    Returns:
        Settings instance.

    Raises:
        ValidationError: If required environment variables are not set.
    """
    # pydantic-settings reads from environment; model_validate handles this
    return Settings.model_validate({})


def _load_trigger_settings() -> TriggerSettings:
    """Load trigger settings from environment."""
    return TriggerSettings.model_validate({})


@lru_cache
def get_settings() -> Settings:
    """Get cached settings instance.

    Returns:
        Cached Settings instance loaded from environment.

    Raises:
        ValidationError: If required environment variables are not set.
    """
    return _load_settings()


@lru_cache
def get_trigger_settings() -> TriggerSettings:
    """Get cached trigger settings instance."""
    return _load_trigger_settings()


@lru_cache
def get_feature_flags() -> FeatureFlags:
    """Get cached feature flags instance.

    Returns:
        Cached FeatureFlags instance loaded from environment.
    """
    return FeatureFlags.model_validate({})


@lru_cache
def get_calendar_settings() -> CalendarIntegrationSettings:
    """Get cached calendar integration settings instance.

    Returns:
        Cached CalendarIntegrationSettings instance loaded from environment.
    """
    return CalendarIntegrationSettings.model_validate({})
