{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "entitlement": {
      "anyOf": [
        {
          "oneOf": [
            {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 100,
                  "pattern": "^[a-zA-Z0-9_-]+$"
                },
                "member": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 100,
                  "pattern": "^[a-zA-Z0-9_-]+$"
                },
                "reward": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 100,
                      "pattern": "^[a-zA-Z0-9_-]+$"
                    },
                    "title": {
                      "type": "string"
                    },
                    "tiers": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 100,
                            "pattern": "^[a-zA-Z0-9_-]+$"
                          },
                          "title": {
                            "type": "string"
                          }
                        },
                        "required": ["id", "title"],
                        "additionalProperties": {}
                      }
                    },
                    "inventory": {
                      "type": "object",
                      "properties": {
                        "kind": {
                          "type": "string"
                        }
                      },
                      "required": ["kind"],
                      "additionalProperties": {}
                    },
                    "fulfillment": {
                      "type": "object",
                      "properties": {
                        "kind": {
                          "type": "string"
                        }
                      },
                      "required": ["kind"],
                      "additionalProperties": {}
                    },
                    "key": {
                      "anyOf": [
                        {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 100,
                          "pattern": "^[a-zA-Z0-9_-]+$"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    }
                  },
                  "required": [
                    "id",
                    "title",
                    "tiers",
                    "inventory",
                    "fulfillment"
                  ],
                  "additionalProperties": {}
                },
                "earnedTier": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 100,
                  "pattern": "^[a-zA-Z0-9_-]+$"
                },
                "tier": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 100,
                  "pattern": "^[a-zA-Z0-9_-]+$"
                },
                "revision": {
                  "type": "integer",
                  "minimum": -9007199254740991,
                  "maximum": 9007199254740991
                },
                "status": {
                  "type": "string",
                  "const": "available"
                }
              },
              "required": [
                "id",
                "member",
                "reward",
                "earnedTier",
                "tier",
                "revision",
                "status"
              ],
              "additionalProperties": {}
            },
            {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 100,
                  "pattern": "^[a-zA-Z0-9_-]+$"
                },
                "member": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 100,
                  "pattern": "^[a-zA-Z0-9_-]+$"
                },
                "reward": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 100,
                      "pattern": "^[a-zA-Z0-9_-]+$"
                    },
                    "title": {
                      "type": "string"
                    },
                    "tiers": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 100,
                            "pattern": "^[a-zA-Z0-9_-]+$"
                          },
                          "title": {
                            "type": "string"
                          }
                        },
                        "required": ["id", "title"],
                        "additionalProperties": {}
                      }
                    },
                    "inventory": {
                      "type": "object",
                      "properties": {
                        "kind": {
                          "type": "string"
                        }
                      },
                      "required": ["kind"],
                      "additionalProperties": {}
                    },
                    "fulfillment": {
                      "type": "object",
                      "properties": {
                        "kind": {
                          "type": "string"
                        }
                      },
                      "required": ["kind"],
                      "additionalProperties": {}
                    },
                    "key": {
                      "anyOf": [
                        {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 100,
                          "pattern": "^[a-zA-Z0-9_-]+$"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    }
                  },
                  "required": [
                    "id",
                    "title",
                    "tiers",
                    "inventory",
                    "fulfillment"
                  ],
                  "additionalProperties": {}
                },
                "earnedTier": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 100,
                  "pattern": "^[a-zA-Z0-9_-]+$"
                },
                "tier": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 100,
                  "pattern": "^[a-zA-Z0-9_-]+$"
                },
                "revision": {
                  "type": "integer",
                  "minimum": -9007199254740991,
                  "maximum": 9007199254740991
                },
                "status": {
                  "type": "string",
                  "const": "handing-over"
                },
                "handover": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 100,
                  "pattern": "^[a-zA-Z0-9_-]+$"
                },
                "startedAt": {
                  "type": "number"
                },
                "allocation": {
                  "type": "object",
                  "properties": {
                    "item": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 100,
                      "pattern": "^[a-zA-Z0-9_-]+$"
                    },
                    "label": {
                      "type": "string"
                    }
                  },
                  "required": ["item", "label"],
                  "additionalProperties": {}
                }
              },
              "required": [
                "id",
                "member",
                "reward",
                "earnedTier",
                "tier",
                "revision",
                "status",
                "handover",
                "startedAt"
              ],
              "additionalProperties": {}
            },
            {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 100,
                  "pattern": "^[a-zA-Z0-9_-]+$"
                },
                "member": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 100,
                  "pattern": "^[a-zA-Z0-9_-]+$"
                },
                "reward": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 100,
                      "pattern": "^[a-zA-Z0-9_-]+$"
                    },
                    "title": {
                      "type": "string"
                    },
                    "tiers": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 100,
                            "pattern": "^[a-zA-Z0-9_-]+$"
                          },
                          "title": {
                            "type": "string"
                          }
                        },
                        "required": ["id", "title"],
                        "additionalProperties": {}
                      }
                    },
                    "inventory": {
                      "type": "object",
                      "properties": {
                        "kind": {
                          "type": "string"
                        }
                      },
                      "required": ["kind"],
                      "additionalProperties": {}
                    },
                    "fulfillment": {
                      "type": "object",
                      "properties": {
                        "kind": {
                          "type": "string"
                        }
                      },
                      "required": ["kind"],
                      "additionalProperties": {}
                    },
                    "key": {
                      "anyOf": [
                        {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 100,
                          "pattern": "^[a-zA-Z0-9_-]+$"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    }
                  },
                  "required": [
                    "id",
                    "title",
                    "tiers",
                    "inventory",
                    "fulfillment"
                  ],
                  "additionalProperties": {}
                },
                "earnedTier": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 100,
                  "pattern": "^[a-zA-Z0-9_-]+$"
                },
                "tier": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 100,
                  "pattern": "^[a-zA-Z0-9_-]+$"
                },
                "revision": {
                  "type": "integer",
                  "minimum": -9007199254740991,
                  "maximum": 9007199254740991
                },
                "status": {
                  "type": "string",
                  "const": "collected"
                },
                "handover": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 100,
                  "pattern": "^[a-zA-Z0-9_-]+$"
                },
                "startedAt": {
                  "type": "number"
                },
                "allocation": {
                  "type": "object",
                  "properties": {
                    "item": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 100,
                      "pattern": "^[a-zA-Z0-9_-]+$"
                    },
                    "label": {
                      "type": "string"
                    }
                  },
                  "required": ["item", "label"],
                  "additionalProperties": {}
                },
                "collectedAt": {
                  "type": "number"
                },
                "recovery": {
                  "type": "object",
                  "properties": {
                    "completion": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 100,
                      "pattern": "^[a-zA-Z0-9_-]+$"
                    },
                    "reason": {
                      "type": "string"
                    },
                    "flaggedAt": {
                      "type": "number"
                    },
                    "remainingTier": {
                      "anyOf": [
                        {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 100,
                          "pattern": "^[a-zA-Z0-9_-]+$"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    }
                  },
                  "required": [
                    "completion",
                    "reason",
                    "flaggedAt",
                    "remainingTier"
                  ]
                }
              },
              "required": [
                "id",
                "member",
                "reward",
                "earnedTier",
                "tier",
                "revision",
                "status",
                "handover",
                "startedAt",
                "collectedAt"
              ],
              "additionalProperties": {}
            },
            {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 100,
                  "pattern": "^[a-zA-Z0-9_-]+$"
                },
                "member": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 100,
                  "pattern": "^[a-zA-Z0-9_-]+$"
                },
                "reward": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 100,
                      "pattern": "^[a-zA-Z0-9_-]+$"
                    },
                    "title": {
                      "type": "string"
                    },
                    "tiers": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 100,
                            "pattern": "^[a-zA-Z0-9_-]+$"
                          },
                          "title": {
                            "type": "string"
                          }
                        },
                        "required": ["id", "title"],
                        "additionalProperties": {}
                      }
                    },
                    "inventory": {
                      "type": "object",
                      "properties": {
                        "kind": {
                          "type": "string"
                        }
                      },
                      "required": ["kind"],
                      "additionalProperties": {}
                    },
                    "fulfillment": {
                      "type": "object",
                      "properties": {
                        "kind": {
                          "type": "string"
                        }
                      },
                      "required": ["kind"],
                      "additionalProperties": {}
                    },
                    "key": {
                      "anyOf": [
                        {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 100,
                          "pattern": "^[a-zA-Z0-9_-]+$"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    }
                  },
                  "required": [
                    "id",
                    "title",
                    "tiers",
                    "inventory",
                    "fulfillment"
                  ],
                  "additionalProperties": {}
                },
                "earnedTier": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 100,
                  "pattern": "^[a-zA-Z0-9_-]+$"
                },
                "tier": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 100,
                  "pattern": "^[a-zA-Z0-9_-]+$"
                },
                "revision": {
                  "type": "integer",
                  "minimum": -9007199254740991,
                  "maximum": 9007199254740991
                },
                "status": {
                  "type": "string",
                  "const": "void"
                },
                "voidedAt": {
                  "type": "number"
                }
              },
              "required": [
                "id",
                "member",
                "reward",
                "earnedTier",
                "tier",
                "revision",
                "status",
                "voidedAt"
              ],
              "additionalProperties": {}
            }
          ]
        },
        {}
      ]
    },
    "inventory": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "untracked"
            }
          },
          "required": ["kind"],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "at-pickup"
            },
            "revision": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "variants": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "item": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100,
                    "pattern": "^[a-zA-Z0-9_-]+$"
                  },
                  "label": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 80
                  },
                  "available": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9007199254740991
                  }
                },
                "required": ["item", "label", "available"]
              }
            }
          },
          "required": ["kind", "revision", "variants"],
          "additionalProperties": false
        }
      ]
    },
    "expiresAt": {
      "type": "number"
    }
  },
  "required": ["entitlement", "inventory", "expiresAt"]
}
