{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://formroost.com/docs/webhooks/schemas/submission.created.v1.json",
  "title": "submission.created.v1",
  "description": "CloudEvents 1.0 payload delivered when a form submission is accepted.",
  "type": "object",
  "required": [
    "specversion",
    "id",
    "source",
    "type",
    "datacontenttype",
    "dataschema",
    "time",
    "subject",
    "data"
  ],
  "properties": {
    "specversion": {
      "const": "1.0"
    },
    "id": {
      "type": "string",
      "description": "Stable event identifier (evt_...) suitable for receiver deduplication."
    },
    "source": {
      "type": "string",
      "description": "Form resource URI (/forms/fpub_...)."
    },
    "type": {
      "const": "com.formroost.submission.created.v1"
    },
    "datacontenttype": {
      "const": "application/json"
    },
    "dataschema": {
      "const": "/docs/webhooks/schemas/submission.created.v1.json"
    },
    "time": {
      "type": "string",
      "format": "date-time"
    },
    "subject": {
      "type": "string",
      "description": "Submission receipt identifier (rcpt_...)."
    },
    "data": {
      "type": "object",
      "required": ["receiptId", "environment", "fields", "metadata"],
      "properties": {
        "receiptId": { "type": "string" },
        "environment": { "enum": ["sandbox", "production"] },
        "fields": {
          "type": "object",
          "additionalProperties": true
        },
        "metadata": {
          "type": "object",
          "properties": {
            "origin": { "type": "string" },
            "referrer": { "type": "string" }
          },
          "additionalProperties": true
        }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}
