{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "oneOf": [
    {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^gr_[0-7][0-9A-HJKMNP-TV-Z]{25}(?![\\s\\S])"
        },
        "revision": {
          "type": "integer",
          "exclusiveMinimum": 0,
          "maximum": 9007199254740991
        },
        "handle": {
          "type": "string",
          "maxLength": 294,
          "pattern": "^autonym:[a-z2-7]{32}@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$"
        },
        "client_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 2048
        },
        "purpose": {
          "type": "object",
          "properties": {
            "category": {
              "type": "string",
              "enum": [
                "booking",
                "recommendation",
                "safety",
                "fulfilment",
                "personalisation",
                "research",
                "care",
                "medical",
                "employment",
                "advertising"
              ]
            },
            "text": {
              "type": "string",
              "minLength": 1,
              "maxLength": 4096
            }
          },
          "required": [
            "category",
            "text"
          ],
          "additionalProperties": false
        },
        "issued_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))$"
        },
        "expires_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))$"
        },
        "status": {
          "type": "string",
          "enum": [
            "active",
            "revoked",
            "expired"
          ]
        },
        "kind": {
          "type": "string",
          "const": "read"
        },
        "read": {
          "minItems": 1,
          "maxItems": 32,
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "domain": {
                "anyOf": [
                  {
                    "type": "string",
                    "pattern": "^[a-z][a-z0-9_.-]{0,63}$"
                  },
                  {
                    "type": "string",
                    "const": "*"
                  }
                ]
              },
              "keys": {
                "anyOf": [
                  {
                    "minItems": 1,
                    "maxItems": 128,
                    "type": "array",
                    "items": {
                      "type": "string",
                      "pattern": "^[a-z][a-z0-9_.-]{0,63}$"
                    }
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "max_level": {
                "type": "string",
                "enum": [
                  "L0",
                  "L1",
                  "L2",
                  "L3"
                ]
              }
            },
            "required": [
              "domain",
              "keys",
              "max_level"
            ],
            "additionalProperties": false
          }
        },
        "declared_only": {
          "type": "boolean"
        },
        "min_confidence": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        },
        "max_reads": {
          "type": "integer",
          "exclusiveMinimum": 0,
          "maximum": 100000
        },
        "reads_used": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "persist_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"
            }
          ]
        },
        "allow_delegation": {
          "type": "boolean"
        },
        "onward_share": {
          "type": "boolean",
          "const": false
        }
      },
      "required": [
        "id",
        "revision",
        "handle",
        "client_id",
        "purpose",
        "issued_at",
        "expires_at",
        "status",
        "kind",
        "read",
        "declared_only",
        "min_confidence",
        "max_reads",
        "reads_used",
        "persist_until",
        "allow_delegation",
        "onward_share"
      ],
      "additionalProperties": false
    },
    {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^gr_[0-7][0-9A-HJKMNP-TV-Z]{25}(?![\\s\\S])"
        },
        "revision": {
          "type": "integer",
          "exclusiveMinimum": 0,
          "maximum": 9007199254740991
        },
        "handle": {
          "type": "string",
          "maxLength": 294,
          "pattern": "^autonym:[a-z2-7]{32}@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$"
        },
        "client_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 2048
        },
        "purpose": {
          "type": "object",
          "properties": {
            "category": {
              "type": "string",
              "enum": [
                "booking",
                "recommendation",
                "safety",
                "fulfilment",
                "personalisation",
                "research",
                "care",
                "medical",
                "employment",
                "advertising"
              ]
            },
            "text": {
              "type": "string",
              "minLength": 1,
              "maxLength": 4096
            }
          },
          "required": [
            "category",
            "text"
          ],
          "additionalProperties": false
        },
        "issued_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))$"
        },
        "expires_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))$"
        },
        "status": {
          "type": "string",
          "enum": [
            "active",
            "revoked",
            "expired"
          ]
        },
        "kind": {
          "type": "string",
          "const": "contribute"
        },
        "contribute": {
          "minItems": 1,
          "maxItems": 32,
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "domain": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_.-]{0,63}$"
              },
              "keys": {
                "minItems": 1,
                "maxItems": 128,
                "type": "array",
                "items": {
                  "type": "string",
                  "pattern": "^[a-z][a-z0-9_.-]{0,63}$"
                }
              }
            },
            "required": [
              "domain",
              "keys"
            ],
            "additionalProperties": false
          }
        },
        "max_events": {
          "type": "integer",
          "exclusiveMinimum": 0,
          "maximum": 100000
        },
        "events_used": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "allow_confirmation": {
          "type": "boolean"
        },
        "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})$"
        }
      },
      "required": [
        "id",
        "revision",
        "handle",
        "client_id",
        "purpose",
        "issued_at",
        "expires_at",
        "status",
        "kind",
        "contribute",
        "max_events",
        "events_used",
        "allow_confirmation",
        "stream_id"
      ],
      "additionalProperties": false
    }
  ]
}
