"""The photo region of a route, from its own first point -- offline, no
network (like route_timezone.py). Used only to choose a Mission Control
hero photo (aventurro/journey_visuals.js AVENTURRO_DEFAULT_HERO_POOL): a
photo tagged with a region must never be shown for a Journey elsewhere.

Plain latitude/longitude rectangles, deliberately CONSERVATIVE: each lies
inside the named region, so a point near a border (e.g. Narvik by the
Swedish border, the Lienz Dolomites in Austria) may fall outside every
rectangle and get a "general" photo -- never the reverse. Not a
geographic truth for anything else; nothing in the analysis uses it.
"""

from __future__ import annotations

# (south, north, west, east) in degrees; a point on an edge counts as inside.
Box = tuple[float, float, float, float]

ROUTE_REGIONS: dict[str, tuple[Box, ...]] = {
    # The Dolomites and the eastern Italian Alps around them, kept south of
    # the Austrian border (which dips to ~46.66 N east of 12.2 E).
    "dolomites": (
        (45.95, 46.75, 10.75, 12.2),
        (45.95, 46.62, 12.2, 12.6),
    ),
    # Mainland Norway incl. Lofoten, kept west/north of Sweden, Finland and
    # Russia (the border runs ~11.2 E at 59 N, ~12 E at 62-63 N, ~15-18 E
    # at 66-68 N, and Finland reaches 70.09 N).
    "norway": (
        (57.9, 59.9, 4.5, 11.0),
        (59.9, 62.5, 4.5, 11.8),
        (62.5, 64.5, 4.5, 11.9),
        (64.5, 66.5, 10.0, 13.5),
        (66.5, 69.4, 11.5, 16.5),
        (68.8, 70.2, 16.0, 20.5),
        (70.2, 71.2, 20.5, 29.0),
    ),
    # Argentine and Chilean Patagonia (south of ~39 S).
    "patagonia": ((-55.5, -39.0, -76.0, -63.0),),
    # The Himalayan arc, kept off the Gangetic plain and the Tibetan plateau
    # interior: Kashmir/Ladakh, Uttarakhand, Nepal/Sikkim, Bhutan/Arunachal.
    "himalaya": (
        (32.5, 35.3, 73.5, 78.0),
        (29.5, 31.2, 78.3, 81.0),
        (28.6, 30.5, 81.0, 83.5),
        (27.3, 30.5, 83.5, 88.9),
        (26.9, 29.5, 88.9, 96.5),
    ),
}


def resolve_route_region(latitude: float, longitude: float) -> str | None:
    """The photo region containing this point, or None (a "general" photo)."""
    for region, boxes in ROUTE_REGIONS.items():
        for south, north, west, east in boxes:
            if south <= latitude <= north and west <= longitude <= east:
                return region
    return None
