{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "oneOf": [
    {
      "$ref": "#/$defs/d0_available"
    },
    {
      "$ref": "#/$defs/d9_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"
        }
      }
    },
    "d4_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
          ]
        }
      }
    },
    "d5_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"
        }
      }
    },
    "d7_hash": {
      "type": "string",
      "pattern": "^0x[0-9a-f]{64}$"
    },
    "d6_settlement": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "transactionHash",
        "previousSettledThroughRound",
        "settledThroughRound",
        "activeRoundCount",
        "workAdded",
        "cumulativeWork",
        "firstCompletedBlock",
        "lastCompletedBlock",
        "completedBlockCount",
        "blockHeight",
        "ethereumBlockNumber",
        "blockTimestamp",
        "logIndex",
        "confirmationStatus"
      ],
      "properties": {
        "transactionHash": {
          "$ref": "#/$defs/d7_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"
        }
      }
    },
    "d8_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"
        }
      }
    },
    "d0_available": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "schemaVersion",
        "installationId",
        "status",
        "range",
        "generatedAt",
        "chain",
        "window",
        "summary",
        "recentSettlements",
        "buckets"
      ],
      "properties": {
        "schemaVersion": {
          "const": 3
        },
        "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"
        },
        "window": {
          "anyOf": [
            {
              "$ref": "#/$defs/d4_window"
            },
            {
              "type": "null"
            }
          ]
        },
        "summary": {
          "$ref": "#/$defs/d5_summary"
        },
        "recentSettlements": {
          "type": "array",
          "maxItems": 12,
          "items": {
            "$ref": "#/$defs/d6_settlement"
          }
        },
        "buckets": {
          "type": "array",
          "maxItems": 30,
          "items": {
            "$ref": "#/$defs/d8_bucket"
          }
        }
      }
    },
    "d9_unavailable": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "schemaVersion",
        "installationId",
        "status",
        "range",
        "reason"
      ],
      "properties": {
        "schemaVersion": {
          "const": 3
        },
        "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."
}
