from typing import Dict
import requests


def gdansk_route_names() -> Dict[str, str]:
    """Returns a mapping from route_short_name to route_long_name for ZTM Gdańsk,
    as route_long_names aren't included in the main GTFS."""
    req = requests.get("https://ckan.multimediagdansk.pl/dataset/c24aa637-3619-4dc2-a171-a23eec8f2172/resource/22313c56-5acf-41c7-a5fd-dc5dc72b3851/download/routes.json")  # noqa
    req.raise_for_status()
    all_routes = req.json()

    route_names: Dict[str, str] = {
        "F5": "Żabi Kruk - Westerplatte - Brzeźno",
        "F6": "Targ Rybny - Sobieszewo"}

    for routes in map(lambda i: all_routes[i]["routes"], sorted(all_routes.keys())):
        for route in routes:
            if route["routeShortName"] in route_names:
                continue
            else:
                route_names[route["routeShortName"]] = route["routeLongName"]

    return route_names