#!/bin/sh
# Emit one ICAO's taxiway GeoJSON as base64 (an ascii-safe tunnel over ssh).
# Broker rule: `taxiways-cat [A-Z]{4}`. The backend decodes it into
# storage/taxiways/{icao}-taxiways.geojson.
set -eu
OSM_DIR=/osm-maps

icao="${1:-}"
case "$icao" in
    [A-Z][A-Z][A-Z][A-Z]) ;;
    *) echo "invalid ICAO: '$icao'" >&2; exit 2 ;;
esac

cd "$OSM_DIR" 2>/dev/null || { echo "osm-maps dir not mounted at $OSM_DIR" >&2; exit 4; }
f="${icao}-taxiways.geojson"
[ -f "$f" ] || { echo "no export for $icao (run taxiways-export $icao first)" >&2; exit 3; }

exec base64 "$f"
