{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.nambikk.ai/events/domain-event-envelope.v1.schema.json",
  "title": "Nambikk CPQ domain event envelope",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "id",
    "type",
    "version",
    "occurredAt",
    "source",
    "tenant",
    "correlationId",
    "actor",
    "subject",
    "resource",
    "links"
  ],
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid"
    },
    "type": {
      "type": "string",
      "enum": [
        "catalogue.published",
        "customer_agreement.status_changed",
        "cart.created",
        "cart.status_changed",
        "approval.requested",
        "approval.status_changed",
        "order.created",
        "order.changed",
        "subscription.changed",
        "service.changed",
        "deliverable.changed"
      ]
    },
    "version": {
      "const": 1
    },
    "occurredAt": {
      "type": "string",
      "format": "date-time"
    },
    "source": {
      "const": "nambikk-cpq",
      "description": "The platform that emitted the event."
    },
    "tenant": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_-]{0,62}$"
        }
      }
    },
    "correlationId": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128
    },
    "actor": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "type"
      ],
      "properties": {
        "id": {
          "type": [
            "string",
            "null"
          ]
        },
        "type": {
          "enum": [
            "USER",
            "SERVICE",
            "SYSTEM"
          ]
        }
      }
    },
    "subject": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "type",
        "id"
      ],
      "properties": {
        "type": {
          "type": "string"
        },
        "id": {
          "type": "string"
        },
        "code": {
          "type": "string"
        },
        "number": {
          "type": "string"
        }
      }
    },
    "changes": {
      "type": "object",
      "minProperties": 1,
      "additionalProperties": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "before",
          "after"
        ],
        "properties": {
          "before": {},
          "after": {}
        }
      }
    },
    "resource": {
      "type": "object",
      "minProperties": 1,
      "additionalProperties": true
    },
    "links": {
      "type": "object",
      "additionalProperties": {
        "type": "string",
        "maxLength": 2048
      }
    }
  }
}
