#!/usr/bin/env python3
"""Hängt GPX-Punkte an eine vorhandene Route an."""

import argparse
from collections.abc import Sequence

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


def build_parser() -> argparse.ArgumentParser:
    parser = argparse.ArgumentParser(description="GPX-Punkte an eine Route anhängen")
    add_common_arguments(parser)
    parser.add_argument("--route-id", type=int)
    parser.add_argument("--gpx")
    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)
    gpx = ask_path("GPX-Datei", args.gpx)
    return client.request("POST", f"/api/routes/{route_id}/append", files={"gpx": gpx})


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