{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.xaere.io/schemas/xr-code-v1.schema.json",
  "title": "Xaere signed XR Code payload v1",
  "type": "object",
  "required": ["version", "xr_id", "broadcast_token", "issuer", "project_id", "campaign_id", "issued_at", "expires_at", "intent", "audience", "key_id", "signature"],
  "additionalProperties": false,
  "properties": {
    "version": { "const": 1 },
    "xr_id": { "type": "string", "pattern": "^xr_[A-Za-z0-9_-]{16,}$" },
    "broadcast_token": { "type": "string", "pattern": "^brd_[A-Za-z0-9_-]{16,}$" },
    "issuer": { "type": "string", "minLength": 1, "maxLength": 160 },
    "project_id": { "type": "string", "pattern": "^prj_[A-Za-z0-9_-]{16,}$" },
    "campaign_id": { "type": ["string", "null"], "pattern": "^cmp_[A-Za-z0-9_-]{16,}$" },
    "issued_at": { "type": "string", "format": "date-time" },
    "expires_at": { "type": "string", "format": "date-time" },
    "intent": {
      "type": "object",
      "required": ["type", "action", "resource"],
      "additionalProperties": false,
      "properties": {
        "type": { "type": "string", "minLength": 1, "maxLength": 160 },
        "action": { "type": "string", "minLength": 1, "maxLength": 160 },
        "resource": { "type": "object" }
      }
    },
    "audience": {
      "type": "object",
      "required": ["enabled", "integration_id"],
      "additionalProperties": false,
      "properties": {
        "enabled": { "type": "boolean" },
        "integration_id": { "type": ["string", "null"], "pattern": "^int_[A-Za-z0-9_-]{8,}$" }
      },
      "allOf": [
        { "if": { "properties": { "enabled": { "const": true } }, "required": ["enabled"] }, "then": { "properties": { "integration_id": { "type": "string" } } } },
        { "if": { "properties": { "enabled": { "const": false } }, "required": ["enabled"] }, "then": { "properties": { "integration_id": { "type": "null" } } } }
      ]
    },
    "key_id": { "type": "string", "minLength": 1, "maxLength": 160 },
    "signature": { "type": "string", "pattern": "^[A-Za-z0-9_-]{43,}$" }
  }
}
