{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.leoverlay.com/schemas/unique-price-grouped-overview-v1.schema.json",
  "title": "Unique price overview v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "cycle",
    "snapshotAt",
    "expiresAt",
    "methodologyVersion",
    "catalogueRevision",
    "groups",
    "rollsAvailable"
  ],
  "properties": {
    "schemaVersion": {
      "const": 1
    },
    "cycle": {
      "type": "string",
      "pattern": "^[A-Za-z][A-Za-z0-9]{0,63}$"
    },
    "snapshotAt": {
      "type": [
        "integer",
        "null"
      ],
      "minimum": 0
    },
    "expiresAt": {
      "type": [
        "integer",
        "null"
      ],
      "minimum": 0
    },
    "methodologyVersion": {
      "type": [
        "integer",
        "null"
      ],
      "minimum": 1
    },
    "catalogueRevision": {
      "type": [
        "string",
        "null"
      ],
      "pattern": "^[0-9a-f]{40}$"
    },
    "groups": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/group"
      }
    },
    "rollsAvailable": {
      "type": "boolean"
    }
  },
  "$defs": {
    "price": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "uniqueId",
        "legendaryPotential",
        "status",
        "positivePriceCount",
        "p25Gold",
        "p50Gold",
        "p75Gold",
        "expiresAt"
      ],
      "properties": {
        "uniqueId": {
          "type": "integer",
          "minimum": 0,
          "maximum": 65535
        },
        "legendaryPotential": {
          "type": "integer",
          "minimum": 0,
          "maximum": 4
        },
        "variantAffixIds": {
          "type": "array",
          "maxItems": 2,
          "uniqueItems": true,
          "items": {
            "type": "integer",
            "minimum": 0,
            "maximum": 65535
          },
          "description": "Sorted native variant affix IDs; empty or omitted means the item summary across all variants."
        },
        "status": {
          "enum": [
            "available",
            "last-known",
            "insufficient-data",
            "stale",
            "unavailable"
          ]
        },
        "lastKnownAt": {
          "type": "integer",
          "minimum": 0
        },
        "positivePriceCount": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 0
        },
        "p25Gold": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 1
        },
        "p50Gold": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 1
        },
        "p75Gold": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 1
        },
        "expiresAt": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 0
        },
        "snapshotAt": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 0
        },
        "history": {
          "type": "array",
          "items": {
            "type": "array",
            "prefixItems": [
              {
                "type": "integer",
                "minimum": 0
              },
              {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 1
              }
            ],
            "minItems": 2,
            "maxItems": 2
          }
        }
      }
    },
    "group": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "uniqueId",
        "kind",
        "variantAffixIds",
        "prices",
        "children"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "uniqueId": {
          "type": "integer",
          "minimum": 0,
          "maximum": 65535
        },
        "kind": {
          "enum": [
            "item",
            "variant",
            "roll"
          ]
        },
        "variantAffixIds": {
          "type": "array",
          "maxItems": 2,
          "uniqueItems": true,
          "items": {
            "type": "integer",
            "minimum": 0,
            "maximum": 65535
          },
          "description": "Sorted native variant affix IDs; empty or omitted means the item summary across all variants."
        },
        "prices": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/price"
          }
        },
        "children": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/group"
          }
        },
        "roll": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "rule",
            "bucket"
          ],
          "properties": {
            "bucket": {
              "enum": [
                "match",
                "other"
              ]
            },
            "rule": {
              "$ref": "#/$defs/rollRule"
            }
          }
        }
      }
    },
    "rollRule": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "version",
        "active",
        "experimental",
        "catalogueRevision",
        "modifierCatalogueRevision",
        "conditions"
      ],
      "properties": {
        "version": {
          "type": "integer",
          "minimum": 1
        },
        "active": {
          "type": "boolean"
        },
        "experimental": {
          "type": "boolean"
        },
        "catalogueRevision": {
          "type": "string"
        },
        "modifierCatalogueRevision": {
          "type": "string"
        },
        "conditions": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "rollId",
              "operator",
              "roll",
              "description"
            ],
            "properties": {
              "rollId": {
                "type": "integer"
              },
              "operator": {
                "enum": [
                  ">",
                  "<="
                ]
              },
              "roll": {
                "type": "integer",
                "minimum": 0,
                "maximum": 255
              },
              "description": {
                "type": "string"
              },
              "display": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "statId",
                    "operator",
                    "value",
                    "unit"
                  ],
                  "properties": {
                    "statId": {
                      "type": "string"
                    },
                    "operator": {
                      "enum": [
                        ">=",
                        "<="
                      ]
                    },
                    "value": {
                      "type": "number"
                    },
                    "unit": {
                      "enum": [
                        "percent",
                        "number"
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
