{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.elimi.africa/contracts/events/event-envelope.v1.json",
  "title": "Event envelope",
  "description": "Standard envelope wrapping every outbox row and RabbitMQ message (architecture §20).",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "eventId",
    "eventType",
    "version",
    "occurredAt",
    "producedBy",
    "correlationId",
    "data"
  ],
  "properties": {
    "eventId": {
      "type": "string",
      "description": "ULID — dedupe key for at-least-once delivery"
    },
    "eventType": {
      "type": "string",
      "description": "resource.past_tense_verb naming"
    },
    "version": {
      "type": "integer",
      "minimum": 1,
      "description": "Payload schema version"
    },
    "occurredAt": {
      "type": "string",
      "format": "date-time"
    },
    "producedBy": {
      "type": "string",
      "examples": ["orchestrator", "cap"]
    },
    "correlationId": {
      "type": "string",
      "description": "Ties the event to the originating request trace"
    },
    "data": {
      "type": "object",
      "description": "Event-specific payload (see per-event schemas)"
    }
  }
}
