{
  "openapi": "3.1.0",
  "info": {
    "title": "KURYEP Public API",
    "version": "1.0.0",
    "description": "Public integration endpoints plus the authenticated customer delivery checkout operations required for payment discovery. Other authenticated customer, courier, and administrator operations are not enumerated."
  },
  "x-service-info": {
    "categories": ["travel"],
    "docs": {
      "homepage": "https://kuryep.com",
      "apiReference": "https://kuryep.com/api-docs.txt"
    }
  },
  "servers": [
    {
      "url": "https://api.kuryep.com/api/v1",
      "description": "KURYEP production API"
    }
  ],
  "paths": {
    "/health": {
      "get": {
        "operationId": "getApiHealth",
        "summary": "Check API and dependency health",
        "security": [],
        "responses": {
          "200": {
            "description": "API is ready",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "service": { "const": "kuryep-api" },
                    "status": { "const": "ok" },
                    "database": { "const": "connected" },
                    "auth": { "type": "string" },
                    "integrations": { "type": "object" }
                  },
                  "required": ["service", "status", "database", "auth", "integrations"]
                }
              }
            }
          },
          "503": { "description": "API or a required dependency is degraded" }
        }
      }
    },
    "/locations/search": {
      "get": {
        "operationId": "searchLocations",
        "summary": "Search for pickup or dropoff locations",
        "security": [],
        "parameters": [
          { "name": "q", "in": "query", "required": true, "schema": { "type": "string" }, "description": "Address or place search text" }
        ],
        "responses": {
          "200": { "description": "Location search results", "content": { "application/json": { "schema": { "type": "object" } } } },
          "400": { "description": "Invalid search request" },
          "429": { "description": "Rate limit exceeded" }
        }
      }
    },
    "/locations/reverse": {
      "get": {
        "operationId": "reverseGeocodeLocation",
        "summary": "Resolve coordinates to a location",
        "security": [],
        "parameters": [
          { "name": "lat", "in": "query", "required": true, "schema": { "type": "number", "minimum": -90, "maximum": 90 } },
          { "name": "lng", "in": "query", "required": true, "schema": { "type": "number", "minimum": -180, "maximum": 180 } }
        ],
        "responses": {
          "200": { "description": "Resolved location", "content": { "application/json": { "schema": { "type": "object" } } } },
          "400": { "description": "Invalid coordinates" },
          "429": { "description": "Rate limit exceeded" }
        }
      }
    },
    "/quotes": {
      "post": {
        "operationId": "createDeliveryQuote",
        "summary": "Calculate an estimated delivery price",
        "security": [],
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "type": "object", "description": "Pickup, dropoff, package, and vehicle details used to calculate a quote." } } }
        },
        "responses": {
          "200": { "description": "Delivery estimate", "content": { "application/json": { "schema": { "type": "object" } } } },
          "400": { "description": "Invalid quote request" },
          "429": { "description": "Rate limit exceeded" }
        }
      }
    },
    "/deliveries": {
      "post": {
        "operationId": "createDeliveryAndStartCheckout",
        "summary": "Create a delivery and start Stripe Checkout",
        "description": "Requires an authenticated customer. Pricing is calculated from the accepted delivery quote, and payment is completed by the customer on the returned Stripe-hosted Checkout page.",
        "security": [{ "bearerAuth": [] }],
        "x-payment-info": {
          "intent": "charge",
          "method": "stripe",
          "amount": null,
          "currency": "USD",
          "description": "Dynamic delivery price based on the accepted quote; payment is completed on Stripe Checkout."
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["pickupLabel", "dropoffLabel", "packageType"],
                "properties": {
                  "quoteId": { "type": "string", "format": "uuid" },
                  "pickupLabel": { "type": "string", "minLength": 2, "maxLength": 500 },
                  "pickupLat": { "type": "number" },
                  "pickupLng": { "type": "number" },
                  "dropoffLabel": { "type": "string", "minLength": 2, "maxLength": 500 },
                  "dropoffLat": { "type": "number" },
                  "dropoffLng": { "type": "number" },
                  "packageType": { "type": "string", "minLength": 1, "maxLength": 120 },
                  "packageNotes": { "type": ["string", "null"], "maxLength": 2000 },
                  "tipCents": { "type": "integer", "minimum": 0, "maximum": 100000 },
                  "requestedAt": { "type": "string", "format": "date-time" }
                }
              }
            }
          }
        },
        "responses": {
          "202": { "description": "Delivery is pending payment; response includes the Stripe Checkout URL." },
          "400": { "description": "Invalid delivery details" },
          "401": { "description": "Authentication required" },
          "409": { "description": "Quote expired or already used" },
          "502": { "description": "Could not start Stripe Checkout" }
        }
      }
    },
    "/deliveries/{id}/checkout": {
      "post": {
        "operationId": "restartDeliveryCheckout",
        "summary": "Restart Stripe Checkout for a pending delivery",
        "description": "Requires an authenticated customer who owns the pending delivery. Returns a Stripe-hosted Checkout URL; the delivery charge is dynamic and comes from that delivery.",
        "security": [{ "bearerAuth": [] }],
        "x-payment-info": {
          "intent": "charge",
          "method": "stripe",
          "amount": null,
          "currency": "USD",
          "description": "The existing delivery total is charged through Stripe Checkout."
        },
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }
        ],
        "responses": {
          "200": { "description": "Checkout restarted; response includes the Stripe Checkout URL." },
          "401": { "description": "Authentication required" },
          "404": { "description": "Delivery not found" },
          "409": { "description": "Delivery does not need checkout" },
          "502": { "description": "Could not restart Stripe Checkout" }
        }
      }
    },
    "/public-tracking/{token}": {
      "get": {
        "operationId": "getPublicDeliveryTracking",
        "summary": "Read delivery status from a share token",
        "security": [],
        "parameters": [
          { "name": "token", "in": "path", "required": true, "schema": { "type": "string" }, "description": "Time-limited token created by an authenticated customer" }
        ],
        "responses": {
          "200": { "description": "Public delivery tracking details", "content": { "application/json": { "schema": { "type": "object" } } } },
          "404": { "description": "Token is invalid, expired, or the delivery does not exist" }
        }
      }
    },
    "/marketing/events": {
      "post": {
        "operationId": "recordMarketingEvent",
        "summary": "Record an allowed marketing event",
        "security": [],
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "type": "object", "required": ["event", "source"], "properties": { "event": { "type": "string", "enum": ["page_view", "cta_click", "referral_visit", "signup_start", "order_start"] }, "source": { "type": "string" }, "campaign": { "type": "string" } }, "additionalProperties": false } } }
        },
        "responses": {
          "202": { "description": "Event accepted" },
          "400": { "description": "Unsupported event payload" },
          "429": { "description": "Rate limit exceeded" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": { "type": "http", "scheme": "bearer" }
    }
  }
}
