{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://mandaionline.com/schemas/webhook-event-v1.json",
  "title": "Mandai Webhook Event v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "event_id",
    "sequence",
    "schema_version",
    "environment",
    "type",
    "occurred_at",
    "data"
  ],
  "properties": {
    "event_id": {
      "type": "string",
      "pattern": "^evt_[A-Za-z0-9_-]+$"
    },
    "sequence": {
      "type": "integer",
      "minimum": 1
    },
    "schema_version": {
      "type": "string",
      "const": "1.0"
    },
    "environment": {
      "type": "string",
      "enum": ["production", "sandbox"]
    },
    "type": {
      "type": "string",
      "enum": [
        "message.queued",
        "message.provider_acknowledged",
        "message.delivered",
        "message.failed",
        "message.unknown"
      ]
    },
    "occurred_at": {
      "type": "string",
      "format": "date-time"
    },
    "data": {
      "type": "object",
      "additionalProperties": false,
      "required": ["message_id", "status"],
      "properties": {
        "message_id": {
          "type": "string",
          "pattern": "^msg_[A-Za-z0-9_-]+$"
        },
        "status": {
          "type": "string",
          "enum": ["queued", "provider_acknowledged", "delivered", "failed", "unknown"]
        },
        "reason_code": {
          "type": "string"
        }
      }
    }
  },
  "x-mandai-requirements": ["WEBHOOK-001", "WEBHOOK-003", "WEBHOOK-006"]
}
