"""Helpers for AccuWeather's numeric weather icons.

AccuWeather identifies weather conditions with icon numbers 1-44
(https://developer.accuweather.com/weather-icons). These helpers turn
those numbers into human-readable descriptions and emoji, which is handy
for CLI output, chat bots, and dashboards.

Example:
    >>> from accuweather_client.icons import icon_to_description, icon_to_emoji
    >>> icon_to_description(3)
    'Partly Sunny'
    >>> icon_to_emoji(3)
    '🌤️'
"""

#: Maps AccuWeather icon number -> (official description, emoji).
ICON_MAP: dict[int, tuple[str, str]] = {
    1: ("Sunny", "☀️"),
    2: ("Mostly Sunny", "🌤️"),
    3: ("Partly Sunny", "🌤️"),
    4: ("Intermittent Clouds", "⛅"),
    5: ("Hazy Sunshine", "🌥️"),
    6: ("Mostly Cloudy", "🌥️"),
    7: ("Cloudy", "☁️"),
    8: ("Dreary (Overcast)", "☁️"),
    11: ("Fog", "🌫️"),
    12: ("Showers", "🌧️"),
    13: ("Mostly Cloudy w/ Showers", "🌦️"),
    14: ("Partly Sunny w/ Showers", "🌦️"),
    15: ("T-Storms", "⛈️"),
    16: ("Mostly Cloudy w/ T-Storms", "⛈️"),
    17: ("Partly Sunny w/ T-Storms", "⛈️"),
    18: ("Rain", "🌧️"),
    19: ("Flurries", "🌨️"),
    20: ("Mostly Cloudy w/ Flurries", "🌨️"),
    21: ("Partly Sunny w/ Flurries", "🌨️"),
    22: ("Snow", "❄️"),
    23: ("Mostly Cloudy w/ Snow", "🌨️"),
    24: ("Ice", "🧊"),
    25: ("Sleet", "🌨️"),
    26: ("Freezing Rain", "🌧️"),
    29: ("Rain and Snow", "🌨️"),
    30: ("Hot", "🥵"),
    31: ("Cold", "🥶"),
    32: ("Windy", "💨"),
    33: ("Clear (Night)", "🌙"),
    34: ("Mostly Clear (Night)", "🌙"),
    35: ("Partly Cloudy (Night)", "☁️"),
    36: ("Intermittent Clouds (Night)", "☁️"),
    37: ("Hazy Moonlight", "🌙"),
    38: ("Mostly Cloudy (Night)", "☁️"),
    39: ("Partly Cloudy w/ Showers (Night)", "🌧️"),
    40: ("Mostly Cloudy w/ Showers (Night)", "🌧️"),
    41: ("Partly Cloudy w/ T-Storms (Night)", "⛈️"),
    42: ("Mostly Cloudy w/ T-Storms (Night)", "⛈️"),
    43: ("Mostly Cloudy w/ Flurries (Night)", "🌨️"),
    44: ("Mostly Cloudy w/ Snow (Night)", "🌨️"),
}


def icon_to_description(icon: int) -> str:
    """Return AccuWeather's official phrase for an icon number.

    Args:
        icon: The AccuWeather weather icon number (1-44).

    Returns:
        The official description, or ``"Unknown"`` for unmapped numbers.
    """
    return ICON_MAP.get(icon, ("Unknown", "❔"))[0]


def icon_to_emoji(icon: int) -> str:
    """Return an emoji that approximates an AccuWeather icon number.

    Args:
        icon: The AccuWeather weather icon number (1-44).

    Returns:
        A single emoji, or ``"❔"`` for unmapped numbers.
    """
    return ICON_MAP.get(icon, ("Unknown", "❔"))[1]
