{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 100,
      "pattern": "^[a-zA-Z0-9_-]+$"
    },
    "key": {
      "type": "string",
      "minLength": 1,
      "maxLength": 100,
      "pattern": "^[a-zA-Z0-9_-]+$"
    },
    "title": {
      "type": "string",
      "minLength": 1,
      "maxLength": 120
    },
    "price": {
      "type": "object",
      "properties": {
        "kind": {
          "default": "points",
          "type": "string",
          "const": "points"
        },
        "balance": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100,
          "pattern": "^[a-zA-Z0-9_-]+$"
        },
        "amount": {
          "type": "integer",
          "exclusiveMinimum": 0,
          "maximum": 2147483647
        }
      },
      "required": ["kind", "balance", "amount"]
    },
    "reward": {
      "type": "object",
      "properties": {
        "kind": {
          "type": "string",
          "const": "tier"
        },
        "reward": {
          "type": "object",
          "properties": {
            "badge": {
              "type": "string",
              "minLength": 1,
              "maxLength": 100,
              "pattern": "^[a-zA-Z0-9_-]+$"
            },
            "group": {
              "type": "string",
              "minLength": 1,
              "maxLength": 100,
              "pattern": "^[a-zA-Z0-9_-]+$"
            },
            "id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 100,
              "pattern": "^[a-zA-Z0-9_-]+$"
            },
            "title": {
              "type": "string",
              "minLength": 1,
              "maxLength": 120
            },
            "tiers": {
              "minItems": 1,
              "maxItems": 20,
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100,
                    "pattern": "^[a-zA-Z0-9_-]+$"
                  },
                  "title": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 120
                  }
                },
                "required": ["id", "title"]
              }
            },
            "inventory": {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "untracked"
                }
              },
              "required": ["kind"]
            },
            "fulfillment": {
              "oneOf": [
                {
                  "type": "object",
                  "properties": {
                    "kind": {
                      "type": "string",
                      "const": "staff-handover"
                    }
                  },
                  "required": ["kind"],
                  "additionalProperties": false
                },
                {
                  "type": "object",
                  "properties": {
                    "kind": {
                      "type": "string",
                      "const": "automatic"
                    }
                  },
                  "required": ["kind"],
                  "additionalProperties": false
                }
              ]
            }
          },
          "required": ["id", "title", "tiers", "inventory", "fulfillment"]
        },
        "tier": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100,
          "pattern": "^[a-zA-Z0-9_-]+$"
        }
      },
      "required": ["kind", "reward", "tier"]
    },
    "stock": {
      "type": "integer",
      "minimum": 0,
      "maximum": 1000000
    },
    "limit": {
      "default": {
        "perMember": 1
      },
      "type": "object",
      "properties": {
        "perMember": {
          "type": "integer",
          "exclusiveMinimum": 0,
          "maximum": 10000
        }
      },
      "required": ["perMember"]
    },
    "requires": {
      "maxItems": 30,
      "type": "array",
      "items": {
        "oneOf": [
          {
            "oneOf": [
              {
                "type": "object",
                "properties": {
                  "kind": {
                    "type": "string",
                    "const": "completion"
                  },
                  "quest": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100,
                    "pattern": "^[a-zA-Z0-9_-]+$"
                  },
                  "scope": {
                    "type": "string",
                    "const": "ever"
                  }
                },
                "required": ["kind", "quest", "scope"],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "kind": {
                    "type": "string",
                    "const": "completion"
                  },
                  "quest": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100,
                    "pattern": "^[a-zA-Z0-9_-]+$"
                  },
                  "scope": {
                    "type": "string",
                    "const": "period"
                  },
                  "period": {
                    "type": "string",
                    "enum": ["day", "week", "month"]
                  }
                },
                "required": ["kind", "quest", "scope", "period"],
                "additionalProperties": false
              }
            ]
          },
          {
            "type": "object",
            "properties": {
              "kind": {
                "type": "string",
                "const": "balance"
              },
              "balance": {
                "type": "string",
                "minLength": 1,
                "maxLength": 100,
                "pattern": "^[a-zA-Z0-9_-]+$"
              },
              "minimum": {
                "type": "integer",
                "exclusiveMinimum": 0,
                "maximum": 9007199254740991
              }
            },
            "required": ["kind", "balance", "minimum"],
            "additionalProperties": false
          },
          {
            "type": "object",
            "properties": {
              "kind": {
                "type": "string",
                "const": "group"
              },
              "group": {
                "type": "string",
                "minLength": 1,
                "maxLength": 100,
                "pattern": "^[a-zA-Z0-9_-]+$"
              },
              "title": {
                "type": "string"
              }
            },
            "required": ["kind", "group", "title"],
            "additionalProperties": false
          }
        ]
      }
    },
    "enabled": {
      "default": true,
      "type": "boolean"
    },
    "revision": {
      "type": "integer",
      "exclusiveMinimum": 0,
      "maximum": 9007199254740991
    },
    "available": {
      "type": "integer",
      "minimum": 0,
      "maximum": 9007199254740991
    },
    "redeemed": {
      "type": "integer",
      "minimum": 0,
      "maximum": 9007199254740991
    },
    "availability": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "available"
            },
            "remaining": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            }
          },
          "required": ["kind", "remaining"],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "out-of-stock"
            }
          },
          "required": ["kind"],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "limit-reached"
            }
          },
          "required": ["kind"],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "paused"
            }
          },
          "required": ["kind"],
          "additionalProperties": false
        }
      ]
    },
    "missing": {
      "default": [],
      "type": "array",
      "items": {
        "anyOf": [
          {
            "type": "object",
            "properties": {
              "kind": {
                "type": "string",
                "const": "completion"
              },
              "quest": {
                "type": "string",
                "minLength": 1,
                "maxLength": 100,
                "pattern": "^[a-zA-Z0-9_-]+$"
              },
              "title": {
                "type": "string"
              },
              "scope": {
                "type": "string",
                "const": "ever"
              }
            },
            "required": ["kind", "quest", "title", "scope"]
          },
          {
            "type": "object",
            "properties": {
              "kind": {
                "type": "string",
                "const": "completion"
              },
              "quest": {
                "type": "string",
                "minLength": 1,
                "maxLength": 100,
                "pattern": "^[a-zA-Z0-9_-]+$"
              },
              "title": {
                "type": "string"
              },
              "scope": {
                "type": "string",
                "const": "period"
              },
              "period": {
                "type": "string",
                "enum": ["day", "week", "month"]
              },
              "resetsAt": {
                "type": "integer",
                "minimum": -9007199254740991,
                "maximum": 9007199254740991
              }
            },
            "required": [
              "kind",
              "quest",
              "title",
              "scope",
              "period",
              "resetsAt"
            ]
          },
          {
            "type": "object",
            "properties": {
              "kind": {
                "type": "string",
                "const": "balance"
              },
              "balance": {
                "type": "string",
                "minLength": 1,
                "maxLength": 100,
                "pattern": "^[a-zA-Z0-9_-]+$"
              },
              "title": {
                "type": "string"
              },
              "minimum": {
                "type": "integer",
                "exclusiveMinimum": 0,
                "maximum": 9007199254740991
              },
              "current": {
                "type": "integer",
                "minimum": 0,
                "maximum": 9007199254740991
              }
            },
            "required": ["kind", "balance", "title", "minimum", "current"]
          },
          {
            "type": "object",
            "properties": {
              "kind": {
                "type": "string",
                "const": "group"
              },
              "group": {
                "type": "string",
                "minLength": 1,
                "maxLength": 100,
                "pattern": "^[a-zA-Z0-9_-]+$"
              },
              "title": {
                "type": "string"
              }
            },
            "required": ["kind", "group", "title"]
          }
        ]
      }
    },
    "archivedAt": {
      "anyOf": [
        {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "required": [
    "id",
    "title",
    "price",
    "reward",
    "stock",
    "limit",
    "enabled",
    "revision",
    "available",
    "redeemed",
    "availability"
  ]
}
