"""Mini-lab: turn a week of weather data from a web API into a forecast with icons.

Weather data by Open-Meteo.com (https://open-meteo.com/), under CC BY 4.0.

Author: YOUR NAME
Version: THE DATE
"""

import requests

FORECAST_URL = "https://api.open-meteo.com/v1/forecast"
HARRISONBURG = (38.4496, -78.8689)  # (latitude, longitude)

# Each category's icon, and the label printed next to it
ICONS = {
    "sunny": ("☀️", "Sunny"),
    "partly cloudy": ("⛅", "Partly cloudy"),
    "cloudy": ("☁️", "Cloudy"),
    "fog": ("🌫️", "Fog"),
    "drizzle": ("🌦️", "Drizzle"),
    "rain": ("🌧️", "Rain"),
    "snow": ("🌨️", "Snow"),
    "storm": ("⛈️", "Thunderstorm"),
    "unknown": ("❔", "Unknown"),
}


def fetch_forecast(latitude: float, longitude: float) -> dict:
    """Request a 7-day daily forecast from Open-Meteo.

    This function is complete. Read it, but don't change it.

    Args:
        latitude: Latitude of the location, in degrees.
        longitude: Longitude of the location, in degrees.

    Returns:
        The JSON response, converted to a dictionary.
    """
    params = {
        "latitude": latitude,
        "longitude": longitude,
        "daily": "weather_code,temperature_2m_max,temperature_2m_min,"
                 "precipitation_probability_max",
        "temperature_unit": "fahrenheit",
        "timezone": "America/New_York",
        "forecast_days": 7,
    }
    response = requests.get(FORECAST_URL, params=params, timeout=10)
    response.raise_for_status()  # Stop with an error if the request failed
    return response.json()


def get_category(code: int) -> str:
    """Translate a WMO weather code into a category of weather.

    Args:
        code: The weather code, such as 61 for rain.

    Returns:
        The category, such as "rain", or "unknown" if the code is not in the
        lab's weather-code table.
    """
    # TODO: Explain in one sentence why you chose if/elif or a dictionary.


def summarize_days(data: dict) -> list[dict]:
    """Reshape the parallel lists of an API response into one dictionary per day.

    Args:
        data: The whole response from fetch_forecast().

    Returns:
        A new list with one dictionary per day, in order. Each has the keys
        "date", "high", "low", "precip" (None if missing), and "category".
    """


def format_day(day: dict) -> str:
    """Describe one day of the forecast on a single line.

    Args:
        day: One dictionary from summarize_days().

    Returns:
        A line such as
        "2026-12-04  High  48°F  Low  29°F  Precip   3%  ☀️ Sunny".
    """


def main() -> None:
    """Show this week's forecast for Harrisonburg, then the details of one day."""


if __name__ == "__main__":
    main()
