{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "archivedAt": {
        "anyOf": [
          {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          },
          {
            "type": "null"
          }
        ]
      },
      "version": {
        "type": "string",
        "minLength": 1,
        "maxLength": 100,
        "pattern": "^[a-zA-Z0-9_-]+$"
      },
      "definition": {
        "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
          },
          "balance": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100,
            "pattern": "^[a-zA-Z0-9_-]+$"
          },
          "score": {
            "default": {
              "kind": "balance"
            },
            "oneOf": [
              {
                "type": "object",
                "properties": {
                  "kind": {
                    "type": "string",
                    "const": "balance"
                  }
                },
                "required": ["kind"],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "kind": {
                    "type": "string",
                    "const": "earned"
                  },
                  "window": {
                    "default": {
                      "kind": "all-time"
                    },
                    "oneOf": [
                      {
                        "type": "object",
                        "properties": {
                          "kind": {
                            "type": "string",
                            "const": "all-time"
                          }
                        },
                        "required": ["kind"],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "kind": {
                            "type": "string",
                            "const": "fixed"
                          },
                          "start": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 8640000000000000
                          },
                          "end": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 8640000000000000
                          }
                        },
                        "required": ["kind", "start", "end"],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "kind": {
                            "type": "string",
                            "const": "rolling"
                          },
                          "days": {
                            "type": "integer",
                            "minimum": 1,
                            "maximum": 9007199254740991
                          }
                        },
                        "required": ["kind", "days"],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "kind": {
                            "type": "string",
                            "const": "calendar"
                          },
                          "period": {
                            "type": "string",
                            "enum": ["day", "week", "month"]
                          }
                        },
                        "required": ["kind", "period"],
                        "additionalProperties": false
                      }
                    ]
                  },
                  "quests": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 100,
                      "pattern": "^[a-zA-Z0-9_-]+$"
                    }
                  }
                },
                "required": ["kind", "window"],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "kind": {
                    "type": "string",
                    "const": "net"
                  },
                  "window": {
                    "default": {
                      "kind": "all-time"
                    },
                    "oneOf": [
                      {
                        "type": "object",
                        "properties": {
                          "kind": {
                            "type": "string",
                            "const": "all-time"
                          }
                        },
                        "required": ["kind"],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "kind": {
                            "type": "string",
                            "const": "fixed"
                          },
                          "start": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 8640000000000000
                          },
                          "end": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 8640000000000000
                          }
                        },
                        "required": ["kind", "start", "end"],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "kind": {
                            "type": "string",
                            "const": "rolling"
                          },
                          "days": {
                            "type": "integer",
                            "minimum": 1,
                            "maximum": 9007199254740991
                          }
                        },
                        "required": ["kind", "days"],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "kind": {
                            "type": "string",
                            "const": "calendar"
                          },
                          "period": {
                            "type": "string",
                            "enum": ["day", "week", "month"]
                          }
                        },
                        "required": ["kind", "period"],
                        "additionalProperties": false
                      }
                    ]
                  }
                },
                "required": ["kind", "window"],
                "additionalProperties": false
              }
            ]
          },
          "access": {
            "default": "participants",
            "type": "string",
            "enum": ["participants", "public"]
          },
          "group": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100,
            "pattern": "^[a-zA-Z0-9_-]+$"
          },
          "includeUnscored": {
            "type": "boolean"
          },
          "ties": {
            "type": "string",
            "enum": ["shared", "earliest"]
          },
          "settle": {
            "type": "object",
            "properties": {
              "at": {
                "type": "string",
                "const": "window-end"
              },
              "ties": {
                "type": "string",
                "enum": ["shared", "earliest"]
              },
              "prizes": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "ranks": {
                      "type": "array",
                      "prefixItems": [
                        {
                          "type": "integer",
                          "exclusiveMinimum": 0,
                          "maximum": 9007199254740991
                        },
                        {
                          "type": "integer",
                          "exclusiveMinimum": 0,
                          "maximum": 9007199254740991
                        }
                      ]
                    },
                    "rewards": {
                      "type": "array",
                      "items": {
                        "anyOf": [
                          {
                            "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",
                                "minimum": 0,
                                "maximum": 9007199254740991
                              }
                            },
                            "required": ["kind", "balance", "amount"]
                          },
                          {
                            "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": {
                                    "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"]
                          }
                        ]
                      }
                    }
                  },
                  "required": ["ranks", "rewards"]
                }
              },
              "pool": {
                "type": "object",
                "properties": {
                  "amount": {
                    "type": "string",
                    "pattern": "^(0|[1-9]\\d{0,77})$"
                  },
                  "unit": {
                    "anyOf": [
                      {
                        "type": "string",
                        "const": "points"
                      },
                      {
                        "type": "object",
                        "properties": {
                          "code": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 32
                          },
                          "decimals": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 9007199254740991
                          }
                        },
                        "required": ["code", "decimals"]
                      }
                    ]
                  },
                  "ledger": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100,
                    "pattern": "^[a-zA-Z0-9_-]+$"
                  },
                  "minScore": {
                    "type": "integer",
                    "minimum": -9007199254740991,
                    "maximum": 9007199254740991
                  }
                },
                "required": ["amount", "unit"]
              }
            },
            "required": ["at", "ties", "prizes"]
          }
        },
        "required": ["id", "title", "balance", "score", "access"]
      },
      "publishedAt": {
        "type": "integer",
        "minimum": 0,
        "maximum": 8640000000000000
      },
      "actor": {
        "anyOf": [
          {
            "type": "string"
          },
          {
            "type": "null"
          }
        ]
      }
    },
    "required": ["version", "definition", "publishedAt", "actor"]
  }
}
