#!/usr/bin/env python3
"""Ändert die Metadaten eines POIs."""

import argparse
from collections.abc import Sequence

from common import add_common_arguments, ask, ask_with_default, client_from_args, run


def build_parser() -> argparse.ArgumentParser:
    parser = argparse.ArgumentParser(description="POI ändern")
    add_common_arguments(parser)
    parser.add_argument("--route-id", type=int)
    parser.add_argument("--poi-id", type=int)
    return parser


def main(argv: Sequence[str] | None = None):
    args = build_parser().parse_args(argv)
    client = client_from_args(args)
    route_id = ask("Route-ID", args.route_id, required=True, cast=int)
    poi_id = ask("POI-ID", args.poi_id, required=True, cast=int)
    path = f"/api/routes/{route_id}/pois/{poi_id}"
    current = client.request("GET", path)
    body = {
        "title": ask_with_default("Titel", current.get("title", "")),
        "description": ask_with_default("Beschreibung", current.get("description", "")),
        "lat": ask_with_default("Breitengrad", current.get("lat"), float),
        "lon": ask_with_default("Längengrad", current.get("lon"), float),
        "triggerRadiusM": ask_with_default("Auslöseradius in Metern", current.get("triggerRadiusM"), float),
        "sequence": ask_with_default("Reihenfolge", current.get("sequence"), int),
    }
    return client.request("PUT", path, json_body=body)


if __name__ == "__main__":
    run(main)
