{
  "openapi": "3.1.0",
  "info": {
    "title": "Cedar Parcel API",
    "version": "1.0.0"
  },
  "security": [
    {
      "ServiceBearer": []
    },
    {
      "ParcelKey": []
    }
  ],
  "tags": [
    {
      "name": "Parcels",
      "description": "Read parcel records."
    }
  ],
  "webhooks": {
    "parcel.delivered": {
      "post": {
        "tags": [
          "Parcels"
        ],
        "summary": "Parcel delivered event",
        "description": "The service sends this event to the receiver's webhook URL.",
        "operationId": "parcelDelivered",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DeliveryEvent"
              },
              "examples": {
                "doorstep": {
                  "summary": "Delivered at doorstep",
                  "value": {
                    "eventId": "evt_demo_001",
                    "parcelId": "pcl_demo_001",
                    "occurredAt": "2026-01-02T10:15:00Z",
                    "outcome": "delivered",
                    "proof": {
                      "kind": "photo",
                      "url": "https://media.cedar-parcel.example/proof/demo.jpg"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "204": {
            "description": "Receiver accepted the event."
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "DeliveryEvent": {
        "type": "object",
        "required": [
          "eventId",
          "parcelId",
          "occurredAt",
          "outcome",
          "proof"
        ],
        "properties": {
          "eventId": {
            "type": "string"
          },
          "parcelId": {
            "type": "string"
          },
          "occurredAt": {
            "type": "string",
            "format": "date-time"
          },
          "outcome": {
            "type": "string",
            "enum": [
              "delivered",
              "returned"
            ]
          },
          "proof": {
            "oneOf": [
              {
                "title": "Photo proof",
                "type": "object",
                "required": [
                  "kind",
                  "url"
                ],
                "properties": {
                  "kind": {
                    "type": "string",
                    "const": "photo"
                  },
                  "url": {
                    "type": "string",
                    "format": "uri"
                  }
                }
              },
              {
                "title": "Signature proof",
                "type": "object",
                "required": [
                  "kind",
                  "signedBy"
                ],
                "properties": {
                  "kind": {
                    "type": "string",
                    "const": "signature"
                  },
                  "signedBy": {
                    "type": "string"
                  }
                }
              }
            ]
          }
        }
      }
    },
    "securitySchemes": {
      "ParcelKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Parcel-Key",
        "description": "Long-lived account key."
      },
      "ServiceBearer": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "Short-lived service token."
      }
    }
  }
}
