{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "leaderboard": {
      "type": "string",
      "minLength": 1,
      "maxLength": 100,
      "pattern": "^[a-zA-Z0-9_-]+$"
    },
    "title": {
      "type": "string"
    },
    "version": {
      "type": "string",
      "minLength": 1,
      "maxLength": 100,
      "pattern": "^[a-zA-Z0-9_-]+$"
    },
    "calculation": {
      "type": "string",
      "enum": ["balance", "earned", "net"]
    },
    "period": {
      "type": "object",
      "properties": {
        "start": {
          "anyOf": [
            {
              "type": "integer",
              "minimum": 0,
              "maximum": 8640000000000000
            },
            {
              "type": "null"
            }
          ]
        },
        "end": {
          "anyOf": [
            {
              "type": "integer",
              "minimum": 0,
              "maximum": 8640000000000000
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": ["start", "end"]
    },
    "calculatedAt": {
      "type": "integer",
      "minimum": 0,
      "maximum": 8640000000000000
    },
    "lastEntryAt": {
      "anyOf": [
        {
          "type": "integer",
          "minimum": 0,
          "maximum": 8640000000000000
        },
        {
          "type": "null"
        }
      ]
    },
    "total": {
      "type": "integer",
      "minimum": 0,
      "maximum": 9007199254740991
    },
    "items": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "participant": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100,
            "pattern": "^[a-zA-Z0-9_-]+$"
          },
          "member": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100,
            "pattern": "^[a-zA-Z0-9_-]+$"
          },
          "name": {
            "type": "string"
          },
          "score": {
            "type": "integer",
            "minimum": -9007199254740991,
            "maximum": 9007199254740991
          },
          "rank": {
            "type": "integer",
            "exclusiveMinimum": 0,
            "maximum": 9007199254740991
          },
          "profile": {
            "anyOf": [
              {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100,
                    "pattern": "^[a-zA-Z0-9_-]+$"
                  },
                  "name": {
                    "type": "string"
                  },
                  "avatar": {
                    "oneOf": [
                      {
                        "type": "object",
                        "properties": {
                          "source": {
                            "type": "string",
                            "const": "upload"
                          },
                          "url": {
                            "type": "string",
                            "format": "uri"
                          },
                          "seed": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 100
                          }
                        },
                        "required": ["source", "url", "seed"],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "source": {
                            "type": "string",
                            "const": "account"
                          },
                          "provider": {
                            "type": "string",
                            "enum": ["x", "discord", "google"]
                          },
                          "url": {
                            "type": "string",
                            "format": "uri"
                          },
                          "seed": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 100
                          }
                        },
                        "required": ["source", "provider", "url", "seed"],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "source": {
                            "type": "string",
                            "const": "generated"
                          },
                          "seed": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 100
                          }
                        },
                        "required": ["source", "seed"],
                        "additionalProperties": false
                      }
                    ]
                  }
                },
                "required": ["id", "name", "avatar"]
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": ["participant", "name", "score", "rank", "profile"]
      }
    },
    "me": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "participant": {
              "type": "string",
              "minLength": 1,
              "maxLength": 100,
              "pattern": "^[a-zA-Z0-9_-]+$"
            },
            "member": {
              "type": "string",
              "minLength": 1,
              "maxLength": 100,
              "pattern": "^[a-zA-Z0-9_-]+$"
            },
            "name": {
              "type": "string"
            },
            "score": {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            "rank": {
              "type": "integer",
              "exclusiveMinimum": 0,
              "maximum": 9007199254740991
            },
            "profile": {
              "anyOf": [
                {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 100,
                      "pattern": "^[a-zA-Z0-9_-]+$"
                    },
                    "name": {
                      "type": "string"
                    },
                    "avatar": {
                      "oneOf": [
                        {
                          "type": "object",
                          "properties": {
                            "source": {
                              "type": "string",
                              "const": "upload"
                            },
                            "url": {
                              "type": "string",
                              "format": "uri"
                            },
                            "seed": {
                              "type": "string",
                              "minLength": 1,
                              "maxLength": 100
                            }
                          },
                          "required": ["source", "url", "seed"],
                          "additionalProperties": false
                        },
                        {
                          "type": "object",
                          "properties": {
                            "source": {
                              "type": "string",
                              "const": "account"
                            },
                            "provider": {
                              "type": "string",
                              "enum": ["x", "discord", "google"]
                            },
                            "url": {
                              "type": "string",
                              "format": "uri"
                            },
                            "seed": {
                              "type": "string",
                              "minLength": 1,
                              "maxLength": 100
                            }
                          },
                          "required": ["source", "provider", "url", "seed"],
                          "additionalProperties": false
                        },
                        {
                          "type": "object",
                          "properties": {
                            "source": {
                              "type": "string",
                              "const": "generated"
                            },
                            "seed": {
                              "type": "string",
                              "minLength": 1,
                              "maxLength": 100
                            }
                          },
                          "required": ["source", "seed"],
                          "additionalProperties": false
                        }
                      ]
                    }
                  },
                  "required": ["id", "name", "avatar"]
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "required": ["participant", "name", "score", "rank", "profile"]
        },
        {
          "type": "null"
        }
      ]
    },
    "nearby": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "participant": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100,
            "pattern": "^[a-zA-Z0-9_-]+$"
          },
          "member": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100,
            "pattern": "^[a-zA-Z0-9_-]+$"
          },
          "name": {
            "type": "string"
          },
          "score": {
            "type": "integer",
            "minimum": -9007199254740991,
            "maximum": 9007199254740991
          },
          "rank": {
            "type": "integer",
            "exclusiveMinimum": 0,
            "maximum": 9007199254740991
          },
          "profile": {
            "anyOf": [
              {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100,
                    "pattern": "^[a-zA-Z0-9_-]+$"
                  },
                  "name": {
                    "type": "string"
                  },
                  "avatar": {
                    "oneOf": [
                      {
                        "type": "object",
                        "properties": {
                          "source": {
                            "type": "string",
                            "const": "upload"
                          },
                          "url": {
                            "type": "string",
                            "format": "uri"
                          },
                          "seed": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 100
                          }
                        },
                        "required": ["source", "url", "seed"],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "source": {
                            "type": "string",
                            "const": "account"
                          },
                          "provider": {
                            "type": "string",
                            "enum": ["x", "discord", "google"]
                          },
                          "url": {
                            "type": "string",
                            "format": "uri"
                          },
                          "seed": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 100
                          }
                        },
                        "required": ["source", "provider", "url", "seed"],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "source": {
                            "type": "string",
                            "const": "generated"
                          },
                          "seed": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 100
                          }
                        },
                        "required": ["source", "seed"],
                        "additionalProperties": false
                      }
                    ]
                  }
                },
                "required": ["id", "name", "avatar"]
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": ["participant", "name", "score", "rank", "profile"]
      }
    },
    "nextCursor": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "required": [
    "leaderboard",
    "title",
    "version",
    "calculation",
    "period",
    "calculatedAt",
    "lastEntryAt",
    "total",
    "items",
    "me",
    "nearby",
    "nextCursor"
  ]
}
