{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "attempts": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100,
            "pattern": "^[a-zA-Z0-9_-]+$"
          },
          "release": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100,
            "pattern": "^[a-zA-Z0-9_-]+$"
          },
          "quest": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100,
            "pattern": "^[a-zA-Z0-9_-]+$"
          },
          "member": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100,
            "pattern": "^[a-zA-Z0-9_-]+$"
          },
          "evidence": {
            "anyOf": [
              {
                "type": "string",
                "minLength": 1,
                "maxLength": 100,
                "pattern": "^[a-zA-Z0-9_-]+$"
              },
              {
                "type": "null"
              }
            ]
          },
          "input": {
            "anyOf": [
              {
                "type": "object",
                "properties": {
                  "kind": {
                    "type": "string",
                    "const": "quiz"
                  },
                  "release": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100,
                    "pattern": "^[a-zA-Z0-9_-]+$"
                  },
                  "answers": {}
                },
                "required": ["kind", "answers"]
              },
              {
                "type": "object",
                "properties": {
                  "kind": {
                    "type": "string",
                    "const": "text"
                  },
                  "value": {
                    "type": "string",
                    "maxLength": 10000
                  }
                },
                "required": ["kind", "value"]
              },
              {
                "type": "object",
                "properties": {
                  "kind": {
                    "type": "string",
                    "const": "url"
                  },
                  "value": {
                    "type": "string",
                    "maxLength": 2048
                  }
                },
                "required": ["kind", "value"]
              }
            ]
          },
          "status": {
            "type": "string"
          },
          "reason": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "retries": {
            "type": "number"
          },
          "generation": {
            "type": "number"
          },
          "completion": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "reviewRewards": {
            "default": null,
            "anyOf": [
              {
                "maxItems": 10,
                "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": 2147483647
                        }
                      },
                      "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": {
                              "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"]
                    },
                    {
                      "type": "object",
                      "properties": {
                        "kind": {
                          "type": "string",
                          "const": "integration"
                        },
                        "provider": {
                          "type": "string",
                          "const": "discord"
                        },
                        "action": {
                          "type": "string",
                          "const": "grant-role"
                        },
                        "roleId": {
                          "type": "string",
                          "pattern": "^[0-9]{1,20}$"
                        }
                      },
                      "required": ["kind", "provider", "action", "roleId"]
                    }
                  ]
                }
              },
              {
                "type": "null"
              }
            ]
          },
          "evaluationRun": {
            "default": 0,
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          },
          "deferCount": {
            "default": 0,
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          },
          "deferUntil": {
            "default": null,
            "anyOf": [
              {
                "type": "integer",
                "minimum": -9007199254740991,
                "maximum": 9007199254740991
              },
              {
                "type": "null"
              }
            ]
          },
          "nextEvaluationAt": {
            "default": null,
            "anyOf": [
              {
                "type": "integer",
                "minimum": -9007199254740991,
                "maximum": 9007199254740991
              },
              {
                "type": "null"
              }
            ]
          },
          "code": {
            "default": null,
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "codeSource": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "progress": {
            "default": null,
            "anyOf": [
              {
                "type": "object",
                "properties": {
                  "current": {
                    "type": "number",
                    "minimum": 0
                  },
                  "target": {
                    "type": "number",
                    "exclusiveMinimum": 0
                  },
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 2000
                  }
                },
                "required": ["current", "target", "reason"]
              },
              {
                "type": "null"
              }
            ]
          },
          "requestedReview": {
            "default": false,
            "type": "boolean"
          },
          "createdAt": {
            "type": "number"
          },
          "questKey": {
            "type": "string"
          },
          "eligibleAt": {
            "type": "integer",
            "minimum": -9007199254740991,
            "maximum": 9007199254740991
          },
          "operatorDecision": {
            "type": "object",
            "properties": {
              "kind": {
                "type": "string"
              },
              "actor": {
                "anyOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "at": {
                "type": "integer",
                "minimum": -9007199254740991,
                "maximum": 9007199254740991
              }
            },
            "required": ["kind", "actor", "at"]
          },
          "rewardsNotSent": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "reason": {
                  "type": "string"
                }
              },
              "required": ["reason"]
            }
          }
        },
        "required": [
          "id",
          "release",
          "quest",
          "member",
          "evidence",
          "status",
          "reason",
          "retries",
          "generation",
          "completion",
          "reviewRewards",
          "evaluationRun",
          "deferCount",
          "deferUntil",
          "nextEvaluationAt",
          "code",
          "progress",
          "requestedReview",
          "createdAt",
          "eligibleAt"
        ]
      }
    },
    "skipped": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "quest": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100,
            "pattern": "^[a-zA-Z0-9_-]+$"
          },
          "questKey": {
            "type": "string"
          },
          "tracker": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100,
            "pattern": "^[a-zA-Z0-9_-]+$"
          },
          "record": {
            "type": "string"
          },
          "code": {
            "type": "string",
            "minLength": 1
          },
          "occurredAt": {
            "type": "integer",
            "minimum": -9007199254740991,
            "maximum": 9007199254740991
          }
        },
        "required": ["quest", "tracker", "record", "code", "occurredAt"]
      }
    },
    "complete": {
      "type": "boolean"
    }
  },
  "required": ["attempts", "skipped", "complete"]
}
