{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://developers.impel.ai/specs/partner-data-share/v1/envelope.schema.json",
  "title": "Webhook envelope",
  "description": "The JSON body of every webhook POST. One envelope carries one batch of events.",
  "type": "object",
  "required": [
    "schema_version",
    "partner",
    "delivery_id",
    "batch_number",
    "total_batches",
    "events"
  ],
  "properties": {
    "schema_version": {
      "description": "Version of this contract. It is the only version marker; individual events don't carry one.",
      "type": "string",
      "const": "1.0"
    },
    "partner": {
      "description": "Your partner identifier, assigned by Impel during onboarding. The same on every request.",
      "type": "string",
      "examples": [
        "example_partner"
      ]
    },
    "delivery_id": {
      "description": "Identifies one delivery run. Every batch sent in the same run, including per-event retries, shares it.",
      "type": "string",
      "format": "uuid",
      "examples": [
        "3d895e79-b121-4528-a7e6-c1533f9b6023"
      ]
    },
    "batch_number": {
      "description": "Position of this batch within the run, starting at 1. A batch that is retried event by event repeats its number, and a batch can be skipped, so don't expect a gap-free sequence.",
      "type": "integer",
      "minimum": 1,
      "examples": [
        1
      ]
    },
    "total_batches": {
      "description": "Number of batches the run planned when it started. Fewer can arrive; treat it as informational.",
      "type": "integer",
      "minimum": 1,
      "examples": [
        3
      ]
    },
    "events": {
      "description": "The events in this batch, oldest first. Each item is told apart by `event_type`: today `message` or `consumer_created`. New event types can be added within this version; skip any you don't recognize.",
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": [
          "event_type",
          "event_timestamp",
          "event_id"
        ],
        "properties": {
          "event_type": {
            "type": "string"
          }
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "event_type": {
                  "const": "message"
                }
              }
            },
            "then": {
              "$ref": "message.schema.json"
            }
          },
          {
            "if": {
              "properties": {
                "event_type": {
                  "const": "consumer_created"
                }
              }
            },
            "then": {
              "$ref": "consumer_created.schema.json"
            }
          }
        ]
      }
    }
  }
}
