"""Deployment preset data model and registry.

Provides curated deployment presets that bundle a set of modules and Helm
flags into named profiles (e.g. "development", "production").  Each preset
can optionally require user input for placeholder values at install time.
"""

from __future__ import annotations

from dataclasses import dataclass


@dataclass(frozen=True)
class DeploymentPreset:
    """Immutable descriptor for a named deployment profile.

    Attributes:
        name: Short identifier, e.g. ``"development"``, ``"production"``.
        description: One-line human-readable summary.
        modules: Modules to enable (references ``ModuleDefinition.name``).
        set_flags: Extra ``--set`` flags to pass to Helm.
        requires_input: Flag keys from *set_flags* whose placeholder value
            (e.g. ``<REGISTRY>``) must be replaced by the user before install.
    """

    name: str
    description: str
    modules: tuple[str, ...]
    set_flags: tuple[str, ...] = ()
    requires_input: tuple[str, ...] = ()


# ---------------------------------------------------------------------------
# Preset definitions
# ---------------------------------------------------------------------------

_DEVELOPMENT = DeploymentPreset(
    name="development",
    description="Lightweight local setup for development and testing",
    modules=("core", "ui", "mongodb", "postgresql", "minio", "jupyter", "gitea", "openldap"),
)

_PRODUCTION = DeploymentPreset(
    name="production",
    description="Hardened setup with security, monitoring, and replication",
    modules=(
        "core",
        "ui",
        "mongodb",
        "postgresql",
        "minio",
        "jupyter",
        "gitea",
        "monitoring",
        "loki",
        "openldap",
    ),
    set_flags=(
        "global.security.enabled=true",
        "ilum-core.replicaCount=2",
    ),
)

_DATA_ENGINEERING = DeploymentPreset(
    name="data-engineering",
    description="Full data stack with SQL, orchestration, and BI tooling",
    modules=(
        "core",
        "ui",
        "mongodb",
        "postgresql",
        "minio",
        "jupyter",
        "gitea",
        "sql",
        "airflow",
        "superset",
        "trino",
        "hive-metastore",
        "openldap",
    ),
)

_AIR_GAPPED = DeploymentPreset(
    name="air-gapped",
    description="Offline deployment with a private container registry",
    modules=("core", "ui", "mongodb", "postgresql", "minio", "jupyter", "gitea"),
    set_flags=("global.imageRegistry=<REGISTRY>",),
    requires_input=("global.imageRegistry",),
)

# ---------------------------------------------------------------------------
# Public registry
# ---------------------------------------------------------------------------

PRESETS: dict[str, DeploymentPreset] = {
    _DEVELOPMENT.name: _DEVELOPMENT,
    _PRODUCTION.name: _PRODUCTION,
    _DATA_ENGINEERING.name: _DATA_ENGINEERING,
    _AIR_GAPPED.name: _AIR_GAPPED,
}


def list_presets() -> list[DeploymentPreset]:
    """Return all presets in display order."""
    return list(PRESETS.values())


def get_preset(name: str) -> DeploymentPreset | None:
    """Look up a preset by *name*, returning ``None`` if not found."""
    return PRESETS.get(name)
