{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 100,
      "pattern": "^[a-zA-Z0-9_-]+$"
    },
    "source": {
      "type": "string"
    },
    "state": {
      "type": "string"
    },
    "status": {
      "type": "string",
      "enum": ["open", "checking", "checked", "applying", "applied", "canceled"]
    },
    "rows": {
      "type": "integer",
      "minimum": 0,
      "maximum": 9007199254740991
    },
    "summary": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "rows": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "ready": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "refused": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "members": {
              "type": "object",
              "properties": {
                "created": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 9007199254740991
                },
                "existing": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 9007199254740991
                }
              },
              "required": ["created", "existing"]
            },
            "accounts": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "points": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "ledger": {
                    "type": "string"
                  },
                  "total": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9007199254740991
                  }
                },
                "required": ["ledger", "total"]
              }
            },
            "actions": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "quest": {
                    "type": "string"
                  },
                  "total": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9007199254740991
                  }
                },
                "required": ["quest", "total"]
              }
            },
            "referrals": {
              "type": "object",
              "properties": {
                "accepted": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 9007199254740991
                },
                "qualified": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "program": {
                        "type": "string"
                      },
                      "total": {
                        "type": "integer",
                        "minimum": 0,
                        "maximum": 9007199254740991
                      }
                    },
                    "required": ["program", "total"]
                  }
                }
              },
              "required": ["accepted", "qualified"]
            },
            "refusals": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "code": {
                    "type": "string"
                  },
                  "rows": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9007199254740991
                  }
                },
                "required": ["code", "rows"]
              }
            }
          },
          "required": [
            "rows",
            "ready",
            "refused",
            "members",
            "accounts",
            "points",
            "actions",
            "refusals"
          ]
        },
        {
          "type": "null"
        }
      ]
    },
    "progress": {
      "type": "object",
      "properties": {
        "applied": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "refused": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        }
      },
      "required": ["applied", "refused"]
    },
    "createdAt": {
      "type": "integer",
      "minimum": -9007199254740991,
      "maximum": 9007199254740991
    },
    "createdBy": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "checkedAt": {
      "anyOf": [
        {
          "type": "integer",
          "minimum": -9007199254740991,
          "maximum": 9007199254740991
        },
        {
          "type": "null"
        }
      ]
    },
    "appliedAt": {
      "anyOf": [
        {
          "type": "integer",
          "minimum": -9007199254740991,
          "maximum": 9007199254740991
        },
        {
          "type": "null"
        }
      ]
    },
    "appliedBy": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "canceledAt": {
      "anyOf": [
        {
          "type": "integer",
          "minimum": -9007199254740991,
          "maximum": 9007199254740991
        },
        {
          "type": "null"
        }
      ]
    },
    "canceledBy": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "stoppedAt": {
      "anyOf": [
        {
          "type": "integer",
          "minimum": -9007199254740991,
          "maximum": 9007199254740991
        },
        {
          "type": "null"
        }
      ]
    },
    "stoppedBy": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "revert": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "reason": {
              "type": "string"
            },
            "requestedAt": {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            "requestedBy": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            },
            "rows": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "revertedAt": {
              "anyOf": [
                {
                  "type": "integer",
                  "minimum": -9007199254740991,
                  "maximum": 9007199254740991
                },
                {
                  "type": "null"
                }
              ]
            },
            "outcome": {
              "anyOf": [
                {
                  "type": "object",
                  "properties": {
                    "reversed": {
                      "type": "object",
                      "properties": {
                        "rows": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991
                        },
                        "entries": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991
                        },
                        "completions": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991
                        },
                        "links": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991
                        }
                      },
                      "required": ["rows", "entries", "completions", "links"]
                    },
                    "unreversedPoints": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "member": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 100,
                            "pattern": "^[a-zA-Z0-9_-]+$"
                          },
                          "ledger": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 100,
                            "pattern": "^[a-zA-Z0-9_-]+$"
                          },
                          "amount": {
                            "type": "integer",
                            "exclusiveMinimum": 0,
                            "maximum": 9007199254740991
                          }
                        },
                        "required": ["member", "ledger", "amount"]
                      }
                    },
                    "keptLinks": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "member": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 100,
                            "pattern": "^[a-zA-Z0-9_-]+$"
                          },
                          "kind": {
                            "type": "string"
                          },
                          "account": {
                            "type": "string"
                          },
                          "reason": {
                            "type": "string"
                          }
                        },
                        "required": ["member", "kind", "account", "reason"]
                      }
                    },
                    "linksUntracked": {
                      "type": "boolean"
                    }
                  },
                  "required": [
                    "reversed",
                    "unreversedPoints",
                    "keptLinks",
                    "linksUntracked"
                  ]
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "required": [
            "reason",
            "requestedAt",
            "requestedBy",
            "rows",
            "revertedAt",
            "outcome"
          ]
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "required": [
    "id",
    "source",
    "status",
    "rows",
    "summary",
    "progress",
    "createdAt",
    "createdBy",
    "checkedAt",
    "appliedAt",
    "appliedBy",
    "canceledAt",
    "canceledBy"
  ]
}
