{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "oneOf": [
    {
      "type": "object",
      "properties": {
        "event_id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{1,128}$"
        },
        "occurred_at": {
          "type": "string",
          "format": "date-time",
          "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
        },
        "stream_id": {
          "type": "string",
          "format": "uuid",
          "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$"
        },
        "domain": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_.-]{0,63}$"
        },
        "key": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_.-]{0,63}$"
        },
        "value_type": {
          "type": "string",
          "enum": [
            "text",
            "number",
            "boolean",
            "enum",
            "list",
            "coded",
            "coded_list",
            "date",
            "date_range",
            "age_band",
            "person_ref",
            "structured",
            "credential"
          ]
        },
        "value": {
          "$ref": "#/$defs/__schema0"
        },
        "context_kind": {
          "type": "string",
          "enum": [
            "fact",
            "preference",
            "state"
          ]
        },
        "temporal": {
          "type": "object",
          "properties": {
            "valid_from": {
              "anyOf": [
                {
                  "type": "string",
                  "format": "date-time",
                  "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
                },
                {
                  "type": "null"
                }
              ]
            },
            "valid_until": {
              "anyOf": [
                {
                  "type": "string",
                  "format": "date-time",
                  "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "required": [
            "valid_from",
            "valid_until"
          ],
          "additionalProperties": false
        },
        "category": {
          "type": "string",
          "enum": [
            "user_supplied",
            "activity",
            "observation",
            "inference"
          ]
        },
        "evidence_refs": {
          "maxItems": 32,
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 256
          }
        },
        "operation": {
          "type": "string",
          "const": "create"
        }
      },
      "required": [
        "event_id",
        "occurred_at",
        "stream_id",
        "domain",
        "key",
        "value_type",
        "value",
        "context_kind",
        "temporal",
        "category",
        "evidence_refs",
        "operation"
      ],
      "additionalProperties": false
    },
    {
      "type": "object",
      "properties": {
        "event_id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{1,128}$"
        },
        "occurred_at": {
          "type": "string",
          "format": "date-time",
          "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
        },
        "stream_id": {
          "type": "string",
          "format": "uuid",
          "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$"
        },
        "domain": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_.-]{0,63}$"
        },
        "key": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_.-]{0,63}$"
        },
        "value_type": {
          "type": "string",
          "enum": [
            "text",
            "number",
            "boolean",
            "enum",
            "list",
            "coded",
            "coded_list",
            "date",
            "date_range",
            "age_band",
            "person_ref",
            "structured",
            "credential"
          ]
        },
        "value": {
          "$ref": "#/$defs/__schema0"
        },
        "context_kind": {
          "type": "string",
          "enum": [
            "fact",
            "preference",
            "state"
          ]
        },
        "temporal": {
          "type": "object",
          "properties": {
            "valid_from": {
              "anyOf": [
                {
                  "type": "string",
                  "format": "date-time",
                  "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
                },
                {
                  "type": "null"
                }
              ]
            },
            "valid_until": {
              "anyOf": [
                {
                  "type": "string",
                  "format": "date-time",
                  "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "required": [
            "valid_from",
            "valid_until"
          ],
          "additionalProperties": false
        },
        "category": {
          "type": "string",
          "enum": [
            "user_supplied",
            "activity",
            "observation",
            "inference"
          ]
        },
        "evidence_refs": {
          "maxItems": 32,
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 256
          }
        },
        "operation": {
          "type": "string",
          "const": "correct"
        },
        "predecessor_event_id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{1,128}$"
        }
      },
      "required": [
        "event_id",
        "occurred_at",
        "stream_id",
        "domain",
        "key",
        "value_type",
        "value",
        "context_kind",
        "temporal",
        "category",
        "evidence_refs",
        "operation",
        "predecessor_event_id"
      ],
      "additionalProperties": false
    },
    {
      "type": "object",
      "properties": {
        "event_id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{1,128}$"
        },
        "occurred_at": {
          "type": "string",
          "format": "date-time",
          "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
        },
        "stream_id": {
          "type": "string",
          "format": "uuid",
          "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$"
        },
        "operation": {
          "type": "string",
          "const": "withdraw"
        },
        "predecessor_event_id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{1,128}$"
        }
      },
      "required": [
        "event_id",
        "occurred_at",
        "stream_id",
        "operation",
        "predecessor_event_id"
      ],
      "additionalProperties": false
    }
  ],
  "$defs": {
    "__schema0": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "number"
        },
        {
          "type": "boolean"
        },
        {
          "type": "null"
        },
        {
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema0"
          }
        },
        {
          "type": "object",
          "propertyNames": {
            "type": "string"
          },
          "additionalProperties": {
            "$ref": "#/$defs/__schema0"
          }
        }
      ]
    }
  }
}
