"""Shared simple-engine choice metadata for creation dialogs.

The labels and descriptions resolve through the translator each time, so the
returned list reflects the currently-active language.
"""

from __future__ import annotations

from typing import List, Tuple

from ..models import EngineType
from ..translator import tr


EngineChoice = Tuple[str, EngineType, str]


# Engine identity tuples without translatable text. Order matters: this is
# the order shown in the combo boxes.
_ENGINE_KEYS: List[Tuple[EngineType, str]] = [
    (EngineType.NETWEAVER, "netweaver"),
    (EngineType.CDP, "cdp"),
    (EngineType.TEMPLATE_2, "portfolio"),
]


def get_simple_engine_choices() -> List[EngineChoice]:
    """Return the engine choices with labels/descriptions in the active language."""
    return [
        (
            tr(f"engines.{slug}.label"),
            engine_type,
            tr(f"engines.{slug}.description"),
        )
        for engine_type, slug in _ENGINE_KEYS
    ]


def engine_description_for_value(engine_value: str) -> str:
    """Return user-facing helper text for a simple engine combo value."""
    for engine_type, slug in _ENGINE_KEYS:
        if engine_type.value == engine_value:
            return tr(f"engines.{slug}.description")
    return ""


def engine_label_for_value(engine_value: str) -> str:
    """Return the translated label for an engine value, or empty string."""
    for engine_type, slug in _ENGINE_KEYS:
        if engine_type.value == engine_value:
            return tr(f"engines.{slug}.label")
    return ""


# Backwards-compatible module-level constant: a snapshot in the language that
# was active at import time. Prefer get_simple_engine_choices() for any new
# code path that should respect runtime language switches.
SIMPLE_ENGINE_CHOICES: List[EngineChoice] = get_simple_engine_choices()
