{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://verifable.eu/feedback/feedback.submit.schema.json",
  "title": "Verifable feedback.submit operation",
  "description": "The complete browser feedback request and receipt contract. Deployment activation is declared separately by the origin-stamped site config.",
  "x-verifable-operation": {
    "id": "feedback.submit",
    "anonymousByDefault": true,
    "hiddenPayloadFields": false,
    "contact": "explicit-opt-in",
    "pageContext": "explicit-opt-in-path-only",
    "deploymentBinding": "origin-stamped-config"
  },
  "$defs": {
    "request": {
      "type": "object",
      "additionalProperties": false,
      "required": ["operation", "contractVersion", "feedback"],
      "properties": {
        "operation": { "const": "feedback.submit" },
        "contractVersion": { "const": "1" },
        "feedback": {
          "type": "object",
          "additionalProperties": false,
          "required": ["kind", "message"],
          "properties": {
            "kind": { "enum": ["problem", "idea", "question", "other"] },
            "message": { "type": "string", "minLength": 1, "maxLength": 5000, "pattern": "\\S" }
          }
        },
        "contact": {
          "type": "object",
          "additionalProperties": false,
          "required": ["email"],
          "properties": { "email": { "type": "string", "format": "email" } }
        },
        "context": {
          "type": "object",
          "additionalProperties": false,
          "required": ["pagePath"],
          "properties": { "pagePath": { "type": "string", "pattern": "^/[^?#]*$" } }
        }
      }
    },
    "recordLinks": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "inspect": { "type": "string", "format": "uri-reference" },
        "export": { "type": "string", "format": "uri-reference" },
        "correct": { "type": "string", "format": "uri-reference" },
        "delete": { "type": "string", "format": "uri-reference" }
      }
    },
    "receipt": {
      "type": "object",
      "additionalProperties": false,
      "required": ["operation", "receiptId", "status", "receivedAt"],
      "properties": {
        "operation": { "const": "feedback.submit" },
        "receiptId": { "type": "string", "minLength": 1 },
        "status": { "enum": ["accepted", "recorded"] },
        "receivedAt": { "type": "string", "format": "date-time" },
        "retention": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "summary": { "type": "string" },
            "until": { "type": "string", "format": "date-time" }
          }
        },
        "records": { "$ref": "#/$defs/recordLinks" }
      }
    },
    "fieldError": {
      "type": "object",
      "additionalProperties": false,
      "required": ["field", "message"],
      "properties": {
        "field": { "type": "string" },
        "message": { "type": "string" }
      }
    },
    "problem": {
      "type": "object",
      "additionalProperties": true,
      "anyOf": [
        { "required": ["code"] },
        { "required": ["title"] },
        { "required": ["detail"] },
        { "required": ["errors"] }
      ],
      "properties": {
        "code": { "type": "string" },
        "title": { "type": "string" },
        "detail": { "type": "string" },
        "errors": { "type": "array", "items": { "$ref": "#/$defs/fieldError" } }
      }
    }
  },
  "oneOf": [
    { "$ref": "#/$defs/request" },
    { "$ref": "#/$defs/receipt" },
    { "$ref": "#/$defs/problem" }
  ]
}
