{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://marvelpbx.invalid/schemas/cem/1.0/event-envelope.schema.json",
  "title": "MarvelPBX CEM Event Envelope 1.0",
  "type": "object",
  "additionalProperties": false,
  "required": ["event_id", "event_type", "event_version", "occurred_at", "received_at", "tenant_id", "customer_id", "deployment_id", "environment", "correlation_id", "causation_id", "producer", "source", "subject", "operation_id", "idempotency_key", "trace_id", "payload", "extensions"],
  "properties": {
    "event_id": {"type": "string", "format": "uuid"},
    "event_type": {"enum": ["communication.call.created", "communication.call.ringing", "communication.call.answered", "communication.call.ended", "recording.detected"]},
    "event_version": {"const": "1.0"},
    "occurred_at": {"type": "string", "format": "date-time"},
    "received_at": {"type": "string", "format": "date-time"},
    "tenant_id": {"type": "string", "minLength": 1},
    "customer_id": {"type": "string", "minLength": 1},
    "deployment_id": {"type": "string", "minLength": 1},
    "environment": {"enum": ["DEV", "TEST", "STAGING", "PROD"]},
    "correlation_id": {"type": "string", "format": "uuid"},
    "causation_id": {"type": ["string", "null"]},
    "producer": {"type": "string", "minLength": 1},
    "source": {"type": "object", "required": ["system", "type", "event_name", "event_id", "occurred_at"]},
    "subject": {"type": "object", "required": ["type", "id"]},
    "operation_id": {"type": "string", "minLength": 1},
    "idempotency_key": {"type": "string", "minLength": 1},
    "trace_id": {"type": "string", "pattern": "^[0-9a-f]{64}$"},
    "payload": {"type": "object"},
    "extensions": {"type": "object"}
  }
}
