"""Named pace profiles: a friendlier name for a pace_factor the existing
terrain pace model (mountain_twin.pace.model.terrain_speed_kmh) already
accepts. This module adds no new terrain mathematics -- it is purely a
registry mapping an (activity, load) label onto the same scalar multiplier
FAST/NOMINAL/SLOW already use (mountain_twin.pace.model.SCENARIO_PACE_FACTORS,
untouched by this module).

The multipliers below are product-chosen, illustrative estimates relative to
NOMINAL_PACE_FACTOR (1.0), not a validated physiological model -- they must
never be presented as scientifically fitted. Deriving them from field data is
future work; the registry shape (a stable profile_id resolving to one
pace_factor) is what this pass establishes.
"""

from __future__ import annotations

from dataclasses import dataclass

from mountain_twin.pace.model import NOMINAL_PACE_FACTOR

REGISTRY_VERSION = "pace_profiles_v0_1"


@dataclass(frozen=True)
class PaceProfile:
    profile_id: str
    display_name_pl: str
    display_name_en: str
    pace_factor: float

    def __post_init__(self) -> None:
        if not self.profile_id:
            raise ValueError("pace profile requires a stable id")
        if self.pace_factor <= 0:
            raise ValueError("pace profile factor must be positive")


PACE_PROFILES: tuple[PaceProfile, ...] = (
    PaceProfile("trail_runner", "Biegacz górski", "Mountain runner", 1.60),
    PaceProfile("fast_hiker", "Szybki piechur", "Fast hiker", 1.20),
    PaceProfile("normal_hiker", "Normalna prędkość", "Normal pace", NOMINAL_PACE_FACTOR),
    PaceProfile("hiker_light_pack", "Piechur z małym plecakiem", "Hiker, light pack", 0.90),
    PaceProfile(
        "slow_hiker_heavy_pack", "Wolny piechur z plecakiem 17 kg", "Slow hiker, 17 kg pack", 0.62
    ),
)

PACE_PROFILES_BY_ID: dict[str, PaceProfile] = {profile.profile_id: profile for profile in PACE_PROFILES}


def pace_factor_for_profile(profile_id: str) -> float:
    """Resolve a named profile to the pace_factor the existing model accepts."""
    try:
        return PACE_PROFILES_BY_ID[profile_id].pace_factor
    except KeyError:
        raise ValueError(f"unknown pace profile: {profile_id}") from None


def pace_profiles_document() -> list[dict[str, object]]:
    """Product-facing listing (profile_id + both display names + factor)."""
    return [
        {
            "profile_id": profile.profile_id,
            "display_name_pl": profile.display_name_pl,
            "display_name_en": profile.display_name_en,
            "pace_factor": profile.pace_factor,
        }
        for profile in PACE_PROFILES
    ]
