{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "Delivery.json",
  "title": "Delivery",
  "description": "One event sent to one endpoint, with its attempt history.",
  "type": "object",
  "properties": {
    "id": {
      "type": "integer",
      "format": "int64",
      "description": "Delivery id. Use it to redeliver."
    },
    "eventId": {
      "type": "string",
      "description": "The event, evt_…. Same as the Flux-Event-Id header."
    },
    "eventType": {
      "type": "string",
      "description": "The event type."
    },
    "status": {
      "type": "string",
      "enum": [
        "pending",
        "delivered",
        "dead",
        "cancelled"
      ],
      "description": "Delivery state."
    },
    "attempts": {
      "type": "integer",
      "format": "int32",
      "description": "Attempts so far. At most 10 before dead, plus any redeliveries."
    },
    "lastStatusCode": {
      "type": [
        "integer",
        "null"
      ],
      "format": "int32",
      "description": "HTTP status of the last attempt."
    },
    "lastError": {
      "type": [
        "string",
        "null"
      ],
      "description": "What went wrong on the last attempt, up to 500 characters."
    },
    "nextAttemptAt": {
      "type": [
        "string",
        "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?$",
      "description": "When the next retry is due. UTC, no offset."
    },
    "lastAttemptAt": {
      "type": [
        "string",
        "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?$",
      "description": "UTC, no offset."
    },
    "deliveredAt": {
      "type": [
        "string",
        "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?$",
      "description": "When your endpoint returned 2xx. UTC, no offset."
    },
    "createdAt": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?$",
      "description": "When the delivery was queued. UTC, no offset."
    }
  },
  "required": [
    "id",
    "eventId",
    "eventType",
    "status",
    "attempts",
    "lastStatusCode",
    "lastError",
    "nextAttemptAt",
    "lastAttemptAt",
    "deliveredAt",
    "createdAt"
  ],
  "examples": [
    {
      "id": 99001,
      "eventId": "evt_01JC8Z5T6Q1W3M4N5P6R7S8T9V",
      "eventType": "invoice.paid",
      "status": "delivered",
      "attempts": 1,
      "lastStatusCode": 200,
      "lastError": null,
      "nextAttemptAt": null,
      "lastAttemptAt": "2026-11-03T14:02:05",
      "deliveredAt": "2026-11-03T14:02:05",
      "createdAt": "2026-11-03T14:02:04"
    }
  ]
}
