{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://developer.reits.tech/schemas/contracts/v1/event-envelope.v1.schema.json",
  "title": "EventEnvelope",
  "type": "object",
  "additionalProperties": false,
  "required": ["eventId", "eventType", "eventVersion", "occurredAt", "producer", "tenantId", "resource", "idempotencyKey", "traceId", "data"],
  "properties": {
    "eventId": { "type": "string", "minLength": 8, "maxLength": 128 },
    "eventType": { "type": "string", "pattern": "^[a-z][a-z0-9-]*(\\.[a-z][a-z0-9-]*){2,}$" },
    "eventVersion": { "type": "integer", "minimum": 1 },
    "occurredAt": { "type": "string", "format": "date-time" },
    "producer": { "type": "string", "minLength": 1, "maxLength": 128 },
    "tenantId": { "type": "string", "minLength": 1, "maxLength": 128 },
    "actor": { "$ref": "#/$defs/resourceRef" },
    "resource": { "$ref": "#/$defs/resourceRef" },
    "idempotencyKey": { "type": "string", "minLength": 1, "maxLength": 256 },
    "traceId": { "type": "string", "minLength": 1, "maxLength": 128 },
    "data": { "type": "object", "additionalProperties": true }
  },
  "$defs": {
    "resourceRef": {
      "type": "object",
      "additionalProperties": false,
      "required": ["type", "id"],
      "properties": {
        "type": { "type": "string", "minLength": 1, "maxLength": 80 },
        "id": { "type": "string", "minLength": 1, "maxLength": 128 }
      }
    }
  }
}
