{
    "openapi": "3.1.0",
    "info": {
        "title": "Ushindi Map Geospatial & Navigation API",
        "version": "1.9.0",
        "description": "Sovereign Angolan geospatial platform API providing deterministic AO Digital Address Codes, batch/reverse geocoding, geofencing & delivery zone checks, verified POI CRUD, 21-province coverage and national highway routing, interactive road & one-way overrides, portable offline province packs (.ushindi.json), live API key usage analytics, fleet ETA matrices, multi-stop optimization, service-area isochrones, GIS GeoJSON/CSV/KML exports, contributor stats, diagnostics, HMAC-SHA256 signed webhooks, and PIN-protected moderation/backup/restore."
    },
    "servers": [
        {
            "url": "/api/v1",
            "description": "Active Ushindi Map API Endpoint"
        }
    ],
    "components": {
        "securitySchemes": {
            "UshindiApiKey": {
                "type": "apiKey",
                "in": "header",
                "name": "X-Ushindi-Key",
                "description": "Optional in sandbox mode; generated via POST /api/v1/keys."
            },
            "ModeratorPin": {
                "type": "apiKey",
                "in": "header",
                "name": "X-Moderator-Pin",
                "description": "Required when approving, rejecting, or flagging permanent map submissions."
            }
        }
    },
    "paths": {
        "/health": {
            "get": {
                "summary": "API v1.1 health, moderation protection flag, and storage status",
                "responses": {
                    "200": {
                        "description": "Healthy response"
                    }
                }
            }
        },
        "/provinces": {
            "get": {
                "summary": "List all 21 official provinces of Angola (2024 Law 14/24)",
                "responses": {
                    "200": {
                        "description": "Array of 21 provinces with bounding boxes and verification coverage"
                    }
                }
            }
        },
        "/address/encode": {
            "get": {
                "summary": "Encode WGS84 coordinates into a deterministic AO Digital Address Code",
                "parameters": [
                    {
                        "name": "lat",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "number"
                        }
                    },
                    {
                        "name": "lng",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "number"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Encoded AO-<PROV>-<LAT>-<LNG> address object"
                    }
                }
            }
        },
        "/address/decode": {
            "get": {
                "summary": "Decode an AO Digital Address Code offline-deterministically back to lat/lng",
                "parameters": [
                    {
                        "name": "code",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Decoded center coordinates and ~1.5m cell bounds"
                    }
                }
            }
        },
        "/address/batch": {
            "post": {
                "summary": "Batch encode coordinates and/or decode AO codes (up to 100 items per call)",
                "responses": {
                    "200": {
                        "description": "Per-item batch results"
                    }
                }
            }
        },
        "/geocode": {
            "get": {
                "summary": "Search Angolan POIs, Centralidades, Bairro + Referencia addresses, and AO codes",
                "parameters": [
                    {
                        "name": "q",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "province",
                        "in": "query",
                        "required": false,
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "limit",
                        "in": "query",
                        "required": false,
                        "schema": {
                            "type": "integer",
                            "default": 10
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Ranked geocoding matches"
                    }
                }
            }
        },
        "/route": {
            "post": {
                "summary": "Calculate passability-aware route with curved road waypoints and pt-AO guidance",
                "responses": {
                    "200": {
                        "description": "Route geometry, ETA, surface breakdown, warnings, and pt-AO turn instructions"
                    }
                }
            }
        },
        "/matrix": {
            "post": {
                "summary": "Compute NxM fleet distance & ETA matrix respecting vehicle passability & rainy season (max 10x10)",
                "responses": {
                    "200": {
                        "description": "2D matrix of distanceKm, estimatedMinutes, and reachable flags"
                    }
                }
            }
        },
        "/pois": {
            "get": {
                "summary": "List verified Angolan POIs and addresses",
                "responses": {
                    "200": {
                        "description": "List of POIs"
                    }
                }
            }
        },
        "/pois/{id}": {
            "patch": {
                "summary": "Update a verified POI (recalculates AO-... code if coordinates change; requires X-Moderator-Pin)",
                "security": [
                    {
                        "ModeratorPin": []
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Updated POI"
                    },
                    "401": {
                        "description": "Invalid or missing X-Moderator-Pin"
                    }
                }
            },
            "delete": {
                "summary": "Delete a POI by ID (requires X-Moderator-Pin)",
                "security": [
                    {
                        "ModeratorPin": []
                    }
                ],
                "responses": {
                    "200": {
                        "description": "POI deleted"
                    },
                    "401": {
                        "description": "Invalid or missing X-Moderator-Pin"
                    }
                }
            }
        },
        "/geofence/check": {
            "post": {
                "summary": "Check whether an AO-... code or lat/lng point falls inside a target province, radius circle, and/or custom GeoJSON polygon",
                "responses": {
                    "200": {
                        "description": "Geofence evaluation result"
                    }
                }
            }
        },
        "/hazards": {
            "get": {
                "summary": "List active real-time road hazards and community confidence",
                "responses": {
                    "200": {
                        "description": "Active hazards"
                    }
                }
            },
            "post": {
                "summary": "Submit a live road hazard report",
                "responses": {
                    "201": {
                        "description": "Created hazard alert"
                    }
                }
            }
        },
        "/hazards/{id}/vote": {
            "post": {
                "summary": "Confirm ('Ainda está lá?') or dismiss ('Já passou') an active hazard",
                "responses": {
                    "200": {
                        "description": "Updated hazard confidence score"
                    }
                }
            }
        },
        "/submissions": {
            "get": {
                "summary": "List permanent map verification submissions",
                "responses": {
                    "200": {
                        "description": "Submissions queue"
                    }
                }
            },
            "post": {
                "summary": "Submit a permanent map edit for field/moderator verification",
                "responses": {
                    "201": {
                        "description": "Created submission"
                    }
                }
            }
        },
        "/submissions/{id}": {
            "patch": {
                "summary": "Approve, reject, or flag a permanent map submission (requires X-Moderator-Pin)",
                "security": [
                    {
                        "ModeratorPin": []
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Updated submission (auto-promotes POIs & road passability overrides)"
                    },
                    "401": {
                        "description": "Invalid or missing X-Moderator-Pin"
                    }
                }
            }
        },
        "/telemetry": {
            "post": {
                "summary": "Submit an anonymized fleet speed probe (no PII)",
                "responses": {
                    "201": {
                        "description": "Aggregated probe recorded"
                    }
                }
            }
        },
        "/telemetry/stats": {
            "get": {
                "summary": "Get anonymized corridor speed statistics across Angola",
                "responses": {
                    "200": {
                        "description": "Corridor speed telemetry summary"
                    }
                }
            }
        },
        "/keys": {
            "post": {
                "summary": "Issue a sandbox B2B API key for an Angolan organization",
                "responses": {
                    "201": {
                        "description": "Issued API key metadata"
                    }
                }
            }
        },
        "/optimize": {
            "post": {
                "summary": "Optimize multi-stop delivery route order (Nearest-Neighbor + 2-opt, max 12 stops)",
                "responses": {
                    "200": {
                        "description": "Ordered stops, legs, km saved, and merged GeoJSON route"
                    }
                }
            }
        },
        "/export/pois.geojson": {
            "get": {
                "summary": "Export all verified POIs as RFC 7946 GeoJSON FeatureCollection",
                "responses": {
                    "200": {
                        "description": "GeoJSON file"
                    }
                }
            }
        },
        "/export/pois.csv": {
            "get": {
                "summary": "Export all verified POIs as UTF-8 CSV",
                "responses": {
                    "200": {
                        "description": "CSV file"
                    }
                }
            }
        },
        "/export/pois.kml": {
            "get": {
                "summary": "Export all verified POIs as KML 2.2 (Google Earth / GIS)",
                "responses": {
                    "200": {
                        "description": "KML 2.2 file"
                    }
                }
            }
        },
        "/admin/backup": {
            "get": {
                "summary": "Download full server JSON backup (requires X-Moderator-Pin)",
                "security": [
                    {
                        "ModeratorPin": []
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Backup archive JSON"
                    },
                    "401": {
                        "description": "Invalid or missing X-Moderator-Pin"
                    }
                }
            }
        },
        "/reverse": {
            "get": {
                "summary": "Reverse geocode WGS84 coordinates into AO code, nearest landmark, and road surface/passability",
                "responses": {
                    "200": {
                        "description": "Reverse geocoded Angolan location"
                    }
                }
            }
        },
        "/isochrone": {
            "post": {
                "summary": "Calculate service-area reachability polygon and covered bairros within maxMinutes",
                "responses": {
                    "200": {
                        "description": "Reachable nodes, bairros, and GeoJSON Polygon"
                    }
                }
            }
        },
        "/stats": {
            "get": {
                "summary": "Get 21-province coverage statistics and field-mapper contributor leaderboard",
                "responses": {
                    "200": {
                        "description": "Platform analytics"
                    }
                }
            }
        },
        "/admin/import-pois": {
            "post": {
                "summary": "Bulk import up to 250 verified POIs with automatic AO-code generation (requires X-Moderator-Pin)",
                "security": [
                    {
                        "ModeratorPin": []
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Import counts and errors"
                    },
                    "401": {
                        "description": "Invalid or missing X-Moderator-Pin"
                    }
                }
            }
        },
        "/roads": {
            "get": {
                "summary": "List road segments merged with live passability & one-way overrides (filterable by ?province=)",
                "responses": {
                    "200": {
                        "description": "Merged road segments across all 21 provinces"
                    }
                }
            }
        },
        "/overrides": {
            "get": {
                "summary": "List active road passability and one-way routing overrides",
                "responses": {
                    "200": {
                        "description": "Active roadOverrides list"
                    }
                }
            },
            "post": {
                "summary": "Create or update a live road passability/surface/one-way override (requires X-Moderator-Pin)",
                "security": [
                    {
                        "ModeratorPin": []
                    }
                ],
                "responses": {
                    "201": {
                        "description": "Saved override"
                    },
                    "401": {
                        "description": "Invalid or missing X-Moderator-Pin"
                    }
                }
            }
        },
        "/overrides/{segmentId}": {
            "delete": {
                "summary": "Remove an active road passability or one-way override (requires X-Moderator-Pin)",
                "security": [
                    {
                        "ModeratorPin": []
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Override removed"
                    }
                }
            }
        },
        "/packs/{provinceCode}": {
            "get": {
                "summary": "Download a portable offline province bundle (.ushindi.json) with verified POIs, hazards, road nodes/segments, and overrides",
                "responses": {
                    "200": {
                        "description": "Offline province pack payload"
                    },
                    "404": {
                        "description": "Unknown province code"
                    }
                }
            }
        },
        "/diagnostics": {
            "get": {
                "summary": "Run cPanel deployment self-diagnostics (PHP version, writable api/data, seed counts, PIN warning)",
                "responses": {
                    "200": {
                        "description": "Diagnostics report"
                    }
                }
            }
        },
        "/route/alternatives": {
            "post": {
                "summary": "Compute fastest, rainy-safe paved, and detour alternative routes with Kwanza (AOA) fuel estimates",
                "responses": {
                    "200": {
                        "description": "Array of alternative routes"
                    }
                }
            }
        },
        "/admin/restore": {
            "post": {
                "summary": "Restore server JSON store from a previous /admin/backup snapshot (requires X-Moderator-Pin)",
                "security": [
                    {
                        "ModeratorPin": []
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Restored store counts"
                    },
                    "401": {
                        "description": "Invalid or missing X-Moderator-Pin"
                    }
                }
            }
        },
        "/webhooks": {
            "get": {
                "summary": "List registered B2B road-hazard webhook subscriptions",
                "responses": {
                    "200": {
                        "description": "Webhooks list"
                    }
                }
            },
            "post": {
                "summary": "Register an SSRF-safe https:// B2B webhook subscription (returns HMAC signingSecret)",
                "responses": {
                    "201": {
                        "description": "Created webhook"
                    }
                }
            }
        },
        "/webhooks/deliveries": {
            "get": {
                "summary": "Audit log of HMAC-SHA256 signed webhook event deliveries",
                "responses": {
                    "200": {
                        "description": "Recent deliveries"
                    }
                }
            }
        },
        "/analytics/usage": {
            "get": {
                "summary": "Live endpoint request counters and per-API-key usage analytics (masked keys, zero PII)",
                "responses": {
                    "200": {
                        "description": "Usage analytics payload"
                    }
                }
            }
        }
    }
}