{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "installationId",
    "revision",
    "generatedAt",
    "measurement",
    "builder",
    "oracle",
    "settlementQueue"
  ],
  "properties": {
    "schemaVersion": {
      "const": 4
    },
    "installationId": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128
    },
    "revision": {
      "type": "string",
      "minLength": 1,
      "maxLength": 256
    },
    "generatedAt": {
      "$ref": "#/$defs/d0_timestamp"
    },
    "measurement": {
      "oneOf": [
        {
          "$ref": "#/$defs/d1_measurement"
        },
        {
          "type": "null"
        }
      ]
    },
    "builder": {
      "oneOf": [
        {
          "$ref": "#/$defs/d3_builderUnavailable"
        },
        {
          "$ref": "#/$defs/d4_builderAvailable"
        }
      ]
    },
    "oracle": {
      "$ref": "#/$defs/d8_oracle"
    },
    "settlementQueue": {
      "oneOf": [
        {
          "$ref": "#/$defs/d10_queueUnavailable"
        },
        {
          "$ref": "#/$defs/d11_queueAvailable"
        }
      ]
    }
  },
  "$defs": {
    "d0_timestamp": {
      "type": "string",
      "format": "date-time"
    },
    "d2_uint64": {
      "type": "string",
      "format": "uint64-decimal"
    },
    "d1_measurement": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "freshness",
        "observedAt",
        "receivedAt",
        "staleAfterSeconds",
        "counterEpoch",
        "cumulativeWorkUnits",
        "provenance",
        "coreStatus",
        "rpmMilli",
        "speedMmPerSecond",
        "distanceMm"
      ],
      "properties": {
        "freshness": {
          "enum": [
            "online",
            "stale"
          ]
        },
        "observedAt": {
          "$ref": "#/$defs/d0_timestamp"
        },
        "receivedAt": {
          "$ref": "#/$defs/d0_timestamp"
        },
        "staleAfterSeconds": {
          "const": 120
        },
        "counterEpoch": {
          "type": "string",
          "format": "uuid"
        },
        "cumulativeWorkUnits": {
          "$ref": "#/$defs/d2_uint64"
        },
        "provenance": {
          "enum": [
            "hardware",
            "simulated",
            "replay",
            "derived"
          ]
        },
        "coreStatus": {
          "enum": [
            "IDLE",
            "ACTIVE",
            "COUNTER_FAULT"
          ]
        },
        "rpmMilli": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "speedMmPerSecond": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "distanceMm": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        }
      }
    },
    "d3_builderUnavailable": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "status",
        "reason"
      ],
      "properties": {
        "status": {
          "const": "unavailable"
        },
        "reason": {
          "enum": [
            "no_measurement",
            "counter_fault",
            "counter_epoch_unapproved",
            "round_projection_gap",
            "oracle_head_unavailable"
          ]
        }
      }
    },
    "d5_uint256": {
      "type": "string",
      "format": "uint256-decimal"
    },
    "d6_hash": {
      "type": "string",
      "pattern": "^0x[0-9a-f]{64}$"
    },
    "d7_projection": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "lifecycle",
        "cumulativeWork",
        "blockHeight",
        "currentWork",
        "workPerBlock",
        "firstCompletedBlock",
        "lastCompletedBlock",
        "completedBlockCount"
      ],
      "properties": {
        "lifecycle": {
          "const": "optimistic"
        },
        "cumulativeWork": {
          "$ref": "#/$defs/d5_uint256"
        },
        "blockHeight": {
          "$ref": "#/$defs/d2_uint64"
        },
        "currentWork": {
          "$ref": "#/$defs/d2_uint64"
        },
        "workPerBlock": {
          "allOf": [
            {
              "$ref": "#/$defs/d2_uint64"
            },
            {
              "not": {
                "const": "0"
              }
            }
          ]
        },
        "firstCompletedBlock": {
          "oneOf": [
            {
              "$ref": "#/$defs/d2_uint64"
            },
            {
              "type": "null"
            }
          ]
        },
        "lastCompletedBlock": {
          "oneOf": [
            {
              "$ref": "#/$defs/d2_uint64"
            },
            {
              "type": "null"
            }
          ]
        },
        "completedBlockCount": {
          "$ref": "#/$defs/d2_uint64"
        }
      }
    },
    "d4_builderAvailable": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "status",
        "anchor",
        "queued",
        "projected"
      ],
      "properties": {
        "status": {
          "const": "available"
        },
        "anchor": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "settledThroughRound",
            "cumulativeWork",
            "blockHeight",
            "currentWork",
            "workPerBlock",
            "confirmedAt",
            "transactionHash"
          ],
          "properties": {
            "settledThroughRound": {
              "$ref": "#/$defs/d2_uint64"
            },
            "cumulativeWork": {
              "$ref": "#/$defs/d5_uint256"
            },
            "blockHeight": {
              "$ref": "#/$defs/d2_uint64"
            },
            "currentWork": {
              "$ref": "#/$defs/d2_uint64"
            },
            "workPerBlock": {
              "allOf": [
                {
                  "$ref": "#/$defs/d2_uint64"
                },
                {
                  "not": {
                    "const": "0"
                  }
                }
              ]
            },
            "confirmedAt": {
              "oneOf": [
                {
                  "$ref": "#/$defs/d0_timestamp"
                },
                {
                  "type": "null"
                }
              ]
            },
            "transactionHash": {
              "oneOf": [
                {
                  "$ref": "#/$defs/d6_hash"
                },
                {
                  "type": "null"
                }
              ]
            }
          }
        },
        "queued": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "closedRoundCount",
            "closedWorkUnits",
            "openRoundWorkUnits"
          ],
          "properties": {
            "closedRoundCount": {
              "$ref": "#/$defs/d2_uint64"
            },
            "closedWorkUnits": {
              "$ref": "#/$defs/d2_uint64"
            },
            "openRoundWorkUnits": {
              "$ref": "#/$defs/d2_uint64"
            }
          }
        },
        "projected": {
          "$ref": "#/$defs/d7_projection"
        }
      }
    },
    "d9_latestClosure": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "firstRound",
        "lastRound",
        "roundCount",
        "acceptedAt"
      ],
      "properties": {
        "firstRound": {
          "$ref": "#/$defs/d2_uint64"
        },
        "lastRound": {
          "$ref": "#/$defs/d2_uint64"
        },
        "roundCount": {
          "$ref": "#/$defs/d2_uint64"
        },
        "acceptedAt": {
          "$ref": "#/$defs/d0_timestamp"
        }
      }
    },
    "d8_oracle": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "state",
        "reason",
        "latestAcceptedAt",
        "latestClosure"
      ],
      "properties": {
        "state": {
          "enum": [
            "accepted",
            "stale",
            "blocked",
            "unavailable"
          ]
        },
        "reason": {
          "enum": [
            null,
            "no_measurement",
            "counter_fault",
            "counter_epoch_unapproved",
            "round_projection_gap",
            "oracle_head_unavailable"
          ]
        },
        "latestAcceptedAt": {
          "anyOf": [
            {
              "$ref": "#/$defs/d0_timestamp"
            },
            {
              "type": "null"
            }
          ]
        },
        "latestClosure": {
          "anyOf": [
            {
              "$ref": "#/$defs/d9_latestClosure"
            },
            {
              "type": "null"
            }
          ]
        }
      }
    },
    "d10_queueUnavailable": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "status",
        "reason"
      ],
      "properties": {
        "status": {
          "const": "unavailable"
        },
        "reason": {
          "enum": [
            "oracle_head_unavailable",
            "round_projection_gap",
            "round_ineligible"
          ]
        }
      }
    },
    "d12_submission": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "submissionId",
        "lifecycle",
        "previousSettledThroughRound",
        "settledThroughRound",
        "roundCount",
        "activeRoundCount",
        "expected",
        "transactionHash",
        "createdAt",
        "submittedAt",
        "confirmedAt",
        "terminalAt",
        "changedAt",
        "outcomeCode"
      ],
      "properties": {
        "submissionId": {
          "type": "string",
          "format": "uuid"
        },
        "lifecycle": {
          "enum": [
            "preparing",
            "submitted",
            "retrying",
            "confirmed",
            "reverted",
            "superseded"
          ]
        },
        "previousSettledThroughRound": {
          "$ref": "#/$defs/d2_uint64"
        },
        "settledThroughRound": {
          "allOf": [
            {
              "$ref": "#/$defs/d2_uint64"
            },
            {
              "not": {
                "const": "0"
              }
            }
          ]
        },
        "roundCount": {
          "allOf": [
            {
              "$ref": "#/$defs/d2_uint64"
            },
            {
              "not": {
                "const": "0"
              }
            }
          ]
        },
        "activeRoundCount": {
          "$ref": "#/$defs/d2_uint64"
        },
        "expected": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "firstCompletedBlock",
            "lastCompletedBlock",
            "completedBlockCount",
            "cumulativeWork",
            "blockHeight",
            "currentWork",
            "workPerBlock"
          ],
          "properties": {
            "firstCompletedBlock": {
              "oneOf": [
                {
                  "$ref": "#/$defs/d2_uint64"
                },
                {
                  "type": "null"
                }
              ]
            },
            "lastCompletedBlock": {
              "oneOf": [
                {
                  "$ref": "#/$defs/d2_uint64"
                },
                {
                  "type": "null"
                }
              ]
            },
            "completedBlockCount": {
              "$ref": "#/$defs/d2_uint64"
            },
            "cumulativeWork": {
              "$ref": "#/$defs/d5_uint256"
            },
            "blockHeight": {
              "$ref": "#/$defs/d2_uint64"
            },
            "currentWork": {
              "$ref": "#/$defs/d2_uint64"
            },
            "workPerBlock": {
              "allOf": [
                {
                  "$ref": "#/$defs/d2_uint64"
                },
                {
                  "not": {
                    "const": "0"
                  }
                }
              ]
            }
          }
        },
        "transactionHash": {
          "oneOf": [
            {
              "$ref": "#/$defs/d6_hash"
            },
            {
              "type": "null"
            }
          ]
        },
        "createdAt": {
          "$ref": "#/$defs/d0_timestamp"
        },
        "submittedAt": {
          "oneOf": [
            {
              "$ref": "#/$defs/d0_timestamp"
            },
            {
              "type": "null"
            }
          ]
        },
        "confirmedAt": {
          "oneOf": [
            {
              "$ref": "#/$defs/d0_timestamp"
            },
            {
              "type": "null"
            }
          ]
        },
        "terminalAt": {
          "oneOf": [
            {
              "$ref": "#/$defs/d0_timestamp"
            },
            {
              "type": "null"
            }
          ]
        },
        "changedAt": {
          "$ref": "#/$defs/d0_timestamp"
        },
        "outcomeCode": {
          "oneOf": [
            {
              "enum": [
                "transaction_reverted",
                "authorization_superseded",
                "canonical_external_advance"
              ]
            },
            {
              "type": "null"
            }
          ]
        }
      }
    },
    "d11_queueAvailable": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "status",
        "state",
        "settlementEnabled",
        "reporterEnvironmentEnabled",
        "buffered",
        "projected",
        "incidentOpen",
        "blockedReason",
        "lastRun",
        "latestSubmission"
      ],
      "properties": {
        "status": {
          "const": "available"
        },
        "state": {
          "enum": [
            "disabled",
            "empty",
            "ready",
            "preparing",
            "submitted",
            "retrying",
            "blocked",
            "stale"
          ]
        },
        "settlementEnabled": {
          "type": "boolean"
        },
        "reporterEnvironmentEnabled": {
          "oneOf": [
            {
              "type": "boolean"
            },
            {
              "type": "null"
            }
          ]
        },
        "buffered": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "firstRound",
            "lastRound",
            "roundCount",
            "activeRoundCount",
            "workUnits"
          ],
          "properties": {
            "firstRound": {
              "oneOf": [
                {
                  "$ref": "#/$defs/d2_uint64"
                },
                {
                  "type": "null"
                }
              ]
            },
            "lastRound": {
              "oneOf": [
                {
                  "$ref": "#/$defs/d2_uint64"
                },
                {
                  "type": "null"
                }
              ]
            },
            "roundCount": {
              "$ref": "#/$defs/d2_uint64"
            },
            "activeRoundCount": {
              "$ref": "#/$defs/d2_uint64"
            },
            "workUnits": {
              "$ref": "#/$defs/d2_uint64"
            }
          }
        },
        "projected": {
          "$ref": "#/$defs/d7_projection"
        },
        "incidentOpen": {
          "type": "boolean"
        },
        "blockedReason": {
          "oneOf": [
            {
              "enum": [
                "settlement_incident",
                "external_anomalous"
              ]
            },
            {
              "type": "null"
            }
          ]
        },
        "lastRun": {
          "oneOf": [
            {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "startedAt",
                "finishedAt",
                "result"
              ],
              "properties": {
                "startedAt": {
                  "oneOf": [
                    {
                      "$ref": "#/$defs/d0_timestamp"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "finishedAt": {
                  "oneOf": [
                    {
                      "$ref": "#/$defs/d0_timestamp"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "result": {
                  "oneOf": [
                    {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 128
                    },
                    {
                      "type": "null"
                    }
                  ]
                }
              }
            },
            {
              "type": "null"
            }
          ]
        },
        "latestSubmission": {
          "oneOf": [
            {
              "$ref": "#/$defs/d12_submission"
            },
            {
              "type": "null"
            }
          ]
        }
      }
    }
  },
  "$comment": "Public response structure from source snapshot 9e38b9313c9b4926ad15c7cd691d7f5789bdbc55. See endpoint notes for semantic constraints."
}
