{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "oneOf": [
    {
      "$ref": "#/$defs/d0_available"
    },
    {
      "$ref": "#/$defs/d13_unavailable"
    }
  ],
  "$defs": {
    "d1_timestamp": {
      "type": "string",
      "format": "date-time"
    },
    "d3_decimal": {
      "type": "string",
      "format": "uint256-decimal"
    },
    "d2_chain": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "target",
        "chainId",
        "confirmations",
        "deploymentBlock",
        "indexedThroughBlock",
        "safeThroughBlock"
      ],
      "properties": {
        "target": {
          "enum": [
            "anvil",
            "sepolia",
            "mainnet"
          ]
        },
        "chainId": {
          "$ref": "#/$defs/d3_decimal"
        },
        "confirmations": {
          "const": "12"
        },
        "deploymentBlock": {
          "$ref": "#/$defs/d3_decimal"
        },
        "indexedThroughBlock": {
          "$ref": "#/$defs/d3_decimal"
        },
        "safeThroughBlock": {
          "$ref": "#/$defs/d3_decimal"
        }
      }
    },
    "d5_address": {
      "type": "string",
      "pattern": "^0x[0-9a-f]{40}$"
    },
    "d4_economy": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "releaseId",
        "mining",
        "token",
        "symbol",
        "decimals"
      ],
      "properties": {
        "releaseId": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9._-]{2,127}$"
        },
        "mining": {
          "$ref": "#/$defs/d5_address"
        },
        "token": {
          "$ref": "#/$defs/d5_address"
        },
        "symbol": {
          "const": "SQK"
        },
        "decimals": {
          "const": 18
        }
      }
    },
    "d6_window": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "startAt",
        "endAt",
        "bucketSeconds"
      ],
      "properties": {
        "startAt": {
          "$ref": "#/$defs/d1_timestamp"
        },
        "endAt": {
          "$ref": "#/$defs/d1_timestamp"
        },
        "bucketSeconds": {
          "enum": [
            3600,
            21600,
            86400
          ]
        }
      }
    },
    "d7_summary": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "settlementCount",
        "activeRoundCount",
        "workAdded",
        "completedBlockCount",
        "archivedSettlementCount"
      ],
      "properties": {
        "settlementCount": {
          "$ref": "#/$defs/d3_decimal"
        },
        "activeRoundCount": {
          "$ref": "#/$defs/d3_decimal"
        },
        "workAdded": {
          "$ref": "#/$defs/d3_decimal"
        },
        "completedBlockCount": {
          "$ref": "#/$defs/d3_decimal"
        },
        "archivedSettlementCount": {
          "$ref": "#/$defs/d3_decimal"
        }
      }
    },
    "d9_hash": {
      "type": "string",
      "pattern": "^0x[0-9a-f]{64}$"
    },
    "d10_mint": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "state",
        "amountBaseUnits"
      ],
      "properties": {
        "state": {
          "enum": [
            "pending",
            "confirmed"
          ]
        },
        "amountBaseUnits": {
          "$ref": "#/$defs/d3_decimal"
        }
      }
    },
    "d8_settlement": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "transactionHash",
        "previousSettledThroughRound",
        "settledThroughRound",
        "activeRoundCount",
        "workAdded",
        "cumulativeWork",
        "firstCompletedBlock",
        "lastCompletedBlock",
        "completedBlockCount",
        "blockHeight",
        "ethereumBlockNumber",
        "blockTimestamp",
        "logIndex",
        "confirmationStatus",
        "mint"
      ],
      "properties": {
        "transactionHash": {
          "$ref": "#/$defs/d9_hash"
        },
        "previousSettledThroughRound": {
          "$ref": "#/$defs/d3_decimal"
        },
        "settledThroughRound": {
          "$ref": "#/$defs/d3_decimal"
        },
        "activeRoundCount": {
          "$ref": "#/$defs/d3_decimal"
        },
        "workAdded": {
          "$ref": "#/$defs/d3_decimal"
        },
        "cumulativeWork": {
          "$ref": "#/$defs/d3_decimal"
        },
        "firstCompletedBlock": {
          "anyOf": [
            {
              "$ref": "#/$defs/d3_decimal"
            },
            {
              "type": "null"
            }
          ]
        },
        "lastCompletedBlock": {
          "anyOf": [
            {
              "$ref": "#/$defs/d3_decimal"
            },
            {
              "type": "null"
            }
          ]
        },
        "completedBlockCount": {
          "$ref": "#/$defs/d3_decimal"
        },
        "blockHeight": {
          "$ref": "#/$defs/d3_decimal"
        },
        "ethereumBlockNumber": {
          "$ref": "#/$defs/d3_decimal"
        },
        "blockTimestamp": {
          "$ref": "#/$defs/d1_timestamp"
        },
        "logIndex": {
          "$ref": "#/$defs/d3_decimal"
        },
        "confirmationStatus": {
          "const": "safe"
        },
        "mint": {
          "$ref": "#/$defs/d10_mint"
        }
      }
    },
    "d11_bucket": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "startAt",
        "endAt",
        "settlementCount",
        "activeRoundCount",
        "workAdded",
        "completedBlockCount"
      ],
      "properties": {
        "startAt": {
          "$ref": "#/$defs/d1_timestamp"
        },
        "endAt": {
          "$ref": "#/$defs/d1_timestamp"
        },
        "settlementCount": {
          "$ref": "#/$defs/d3_decimal"
        },
        "activeRoundCount": {
          "$ref": "#/$defs/d3_decimal"
        },
        "workAdded": {
          "$ref": "#/$defs/d3_decimal"
        },
        "completedBlockCount": {
          "$ref": "#/$defs/d3_decimal"
        }
      }
    },
    "d12_queueProjection": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "state",
        "previousSettledThroughRound",
        "settledThroughRound",
        "activeRoundCount",
        "previousBlockHeight",
        "blockHeight",
        "firstCompletedBlock",
        "lastCompletedBlock",
        "completedBlockCount",
        "amountBaseUnits"
      ],
      "properties": {
        "state": {
          "const": "projected"
        },
        "previousSettledThroughRound": {
          "$ref": "#/$defs/d3_decimal"
        },
        "settledThroughRound": {
          "$ref": "#/$defs/d3_decimal"
        },
        "activeRoundCount": {
          "$ref": "#/$defs/d3_decimal"
        },
        "previousBlockHeight": {
          "$ref": "#/$defs/d3_decimal"
        },
        "blockHeight": {
          "$ref": "#/$defs/d3_decimal"
        },
        "firstCompletedBlock": {
          "anyOf": [
            {
              "$ref": "#/$defs/d3_decimal"
            },
            {
              "type": "null"
            }
          ]
        },
        "lastCompletedBlock": {
          "anyOf": [
            {
              "$ref": "#/$defs/d3_decimal"
            },
            {
              "type": "null"
            }
          ]
        },
        "completedBlockCount": {
          "$ref": "#/$defs/d3_decimal"
        },
        "amountBaseUnits": {
          "$ref": "#/$defs/d3_decimal"
        }
      }
    },
    "d0_available": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "schemaVersion",
        "installationId",
        "status",
        "range",
        "generatedAt",
        "chain",
        "economy",
        "window",
        "summary",
        "recentSettlements",
        "buckets"
      ],
      "properties": {
        "schemaVersion": {
          "const": 4
        },
        "installationId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "status": {
          "const": "available"
        },
        "range": {
          "enum": [
            "now",
            "24h",
            "7d",
            "30d"
          ]
        },
        "generatedAt": {
          "$ref": "#/$defs/d1_timestamp"
        },
        "chain": {
          "$ref": "#/$defs/d2_chain"
        },
        "economy": {
          "$ref": "#/$defs/d4_economy"
        },
        "window": {
          "anyOf": [
            {
              "$ref": "#/$defs/d6_window"
            },
            {
              "type": "null"
            }
          ]
        },
        "summary": {
          "$ref": "#/$defs/d7_summary"
        },
        "recentSettlements": {
          "type": "array",
          "maxItems": 12,
          "items": {
            "$ref": "#/$defs/d8_settlement"
          }
        },
        "buckets": {
          "type": "array",
          "maxItems": 30,
          "items": {
            "$ref": "#/$defs/d11_bucket"
          }
        },
        "queueProjection": {
          "$ref": "#/$defs/d12_queueProjection"
        }
      }
    },
    "d13_unavailable": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "schemaVersion",
        "installationId",
        "status",
        "range",
        "reason"
      ],
      "properties": {
        "schemaVersion": {
          "const": 4
        },
        "installationId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "status": {
          "const": "unavailable"
        },
        "range": {
          "enum": [
            "now",
            "24h",
            "7d",
            "30d"
          ]
        },
        "reason": {
          "enum": [
            "indexer_disabled",
            "not_yet_safe",
            "indexer_unavailable",
            "indexer_mismatch"
          ]
        }
      }
    }
  },
  "$comment": "Public response structure from source snapshot 9e38b9313c9b4926ad15c7cd691d7f5789bdbc55. See endpoint notes for semantic constraints."
}
