{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/statshawk-ai/json-schema/statshawk-ai-public-stat-response-stat-history-page-schema.json",
  "title": "PublicStatResponseStatHistoryPage",
  "description": "Successful response envelope: resource data and source-free request metadata.",
  "x-generated": "2026-11-26",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/statshawk-ai-openapi.json#/components/schemas/PublicStatResponseStatHistoryPage",
  "type": "object",
  "required": [
    "data",
    "meta"
  ],
  "properties": {
    "data": {
      "$ref": "#/$defs/StatHistoryPage",
      "description": "Resource payload returned by this endpoint, inside the success envelope."
    },
    "meta": {
      "$ref": "#/$defs/PublicMeta",
      "description": "Request identifier, fetch timestamp, response cache state and version; never a source."
    }
  },
  "$defs": {
    "AuditContestContext": {
      "type": "object",
      "description": "Contest facts stored with a stat; finality comes from the status alone.",
      "required": [
        "contest_id",
        "edition_id",
        "scheduled_at",
        "stage",
        "status",
        "finality"
      ],
      "properties": {
        "contest_id": {
          "$ref": "#/$defs/ContestId"
        },
        "edition_id": {
          "oneOf": [
            {
              "type": "null",
              "description": "Accepts the JSON null value."
            },
            {
              "$ref": "#/$defs/EditionId"
            }
          ]
        },
        "finality": {
          "$ref": "#/$defs/PublicFinality"
        },
        "scheduled_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "stage": {
          "oneOf": [
            {
              "type": "null",
              "description": "Accepts the JSON null value."
            },
            {
              "$ref": "#/$defs/ContestStage"
            }
          ]
        },
        "status": {
          "oneOf": [
            {
              "type": "null",
              "description": "Accepts the JSON null value."
            },
            {
              "$ref": "#/$defs/ContestStatus"
            }
          ]
        }
      }
    },
    "AuditSupport": {
      "type": "object",
      "description": "Which measures the audit covers.",
      "required": [
        "status",
        "policy_version",
        "enabled_measures",
        "unsupported_measures",
        "enabled_from"
      ],
      "properties": {
        "enabled_from": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "enabled_measures": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/QualifiedMeasure"
          }
        },
        "policy_version": {
          "type": "string"
        },
        "status": {
          "$ref": "#/$defs/SupportStatus"
        },
        "unsupported_measures": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/QualifiedMeasure"
          }
        }
      }
    },
    "BeforeStart": {
      "type": "string",
      "description": "Extent before the history start.",
      "enum": [
        "unknown"
      ]
    },
    "CacheStatus": {
      "type": "string",
      "description": "Response cache status, serialized as an uppercase token.\n`HIT` means a relevant store read or handler response cache returned a cached payload; `MISS` means a cache miss or an uncached read.\n`STALE` means a cached payload passed its fresh TTL but remains inside the allowed stale interval. It does not guarantee a refresh has started. Current entity-store caching records HIT or MISS.\nComposite reads report the last store-call outcome; this does not prove every nested resource shares one fetch time.",
      "enum": [
        "HIT",
        "MISS",
        "STALE"
      ]
    },
    "CalculationMetadata": {
      "type": "object",
      "description": "The registered rule behind a calculated value.",
      "required": [
        "rule_id",
        "version",
        "formula",
        "inputs",
        "aggregation",
        "rounding"
      ],
      "properties": {
        "aggregation": {
          "$ref": "#/$defs/PublicAggregation"
        },
        "formula": {
          "type": "string"
        },
        "inputs": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/QualifiedMeasure"
          }
        },
        "rounding": {
          "$ref": "#/$defs/PublicRounding"
        },
        "rule_id": {
          "$ref": "#/$defs/QualifiedMeasure"
        },
        "version": {
          "type": "integer",
          "format": "int32",
          "minimum": 0
        }
      }
    },
    "CompetitionId": {
      "type": "string",
      "description": "Canonical competition identifier (`comp_…`); competition URL paths generally use the human-readable slug instead.\nCanonical entity identifier (`comp_<base32>`). The suffix is exactly 26 Crockford base32 symbols encoding a UUID. Output uses lowercase without padding. The prefix is case-sensitive; another entity type’s prefix and bare UUID/source identifiers are rejected. Treat the full identifier as opaque."
    },
    "ContestId": {
      "type": "string",
      "description": "Canonical contest identifier (`cst_…`) for a team match, individual match, or field event; used by public contest routes.\nCanonical entity identifier (`cst_<base32>`). The suffix is exactly 26 Crockford base32 symbols encoding a UUID. Output uses lowercase without padding. The prefix is case-sensitive; another entity type’s prefix and bare UUID/source identifiers are rejected. Treat the full identifier as opaque."
    },
    "ContestStage": {
      "type": "string",
      "description": "The competitive stage of a [`Contest`] within its edition:\npreseason/exhibition play folds separately from the regular-season and\npostseason aggregates it would otherwise pollute. Stored nullable — `NULL`\nmeans \"unknown stage\" and is treated as regular-season for fold/read\npurposes so a deploy of this column can precede any backfill.",
      "enum": [
        "preseason",
        "regular",
        "postseason",
        "exhibition",
        "allstar"
      ]
    },
    "ContestStatus": {
      "type": "string",
      "description": "Lifecycle status of a [`Contest`]. Renamed from the legacy `GameStatus`\nwith stable snake_case tokens: `scheduled` means not started; `in_progress` means play has started;\n`final` means completed; `postponed` means delayed to a later start; `cancelled` means cancelled;\n`suspended` means started play has paused.",
      "enum": [
        "scheduled",
        "in_progress",
        "final",
        "postponed",
        "cancelled",
        "suspended"
      ]
    },
    "CoverageStatus": {
      "type": "string",
      "description": "Measure coverage level.",
      "enum": [
        "complete",
        "partial",
        "unknown"
      ]
    },
    "CoverageUnit": {
      "type": "string",
      "description": "What a coverage count counts.",
      "enum": [
        "eligible_appearance_phase_measure",
        "eligible_contest_phase_measure"
      ]
    },
    "EditionId": {
      "type": "string",
      "description": "Edition (season instance of a competition) id (`edt_...`).\nCanonical entity identifier (`edt_<base32>`). The suffix is exactly 26 Crockford base32 symbols encoding a UUID. Output uses lowercase without padding. The prefix is case-sensitive; another entity type’s prefix and bare UUID/source identifiers are rejected. Treat the full identifier as opaque."
    },
    "HistoryStatus": {
      "type": "string",
      "description": "Whether history exists.",
      "enum": [
        "retained_from",
        "unavailable"
      ]
    },
    "MeasureCoverage": {
      "type": "object",
      "description": "How much of the expected set was observed.",
      "required": [
        "status",
        "observed",
        "expected",
        "unit"
      ],
      "properties": {
        "expected": {
          "type": [
            "integer",
            "null"
          ],
          "format": "int64",
          "minimum": 0
        },
        "observed": {
          "type": [
            "integer",
            "null"
          ],
          "format": "int64",
          "minimum": 0
        },
        "status": {
          "$ref": "#/$defs/CoverageStatus"
        },
        "unit": {
          "$ref": "#/$defs/CoverageUnit"
        }
      }
    },
    "PersonId": {
      "type": "string",
      "description": "Canonical sport-agnostic person id (`per_...`).\nCanonical entity identifier (`per_<base32>`). The suffix is exactly 26 Crockford base32 symbols encoding a UUID. Output uses lowercase without padding. The prefix is case-sensitive; another entity type’s prefix and bare UUID/source identifiers are rejected. Treat the full identifier as opaque."
    },
    "PublicAggregation": {
      "type": "string",
      "description": "How a rule combines games.",
      "enum": [
        "additive",
        "additive_observed",
        "ratio_of_sums",
        "formula",
        "max"
      ]
    },
    "PublicAvailability": {
      "type": "string",
      "description": "Measure availability.",
      "enum": [
        "observed",
        "unreported",
        "unsupported",
        "not_applicable",
        "undefined",
        "unknown"
      ]
    },
    "PublicCursor": {
      "type": "string",
      "description": "An opaque continuation token."
    },
    "PublicFinality": {
      "type": "string",
      "description": "Whether the contest is over.",
      "enum": [
        "final",
        "not_final",
        "unknown"
      ]
    },
    "PublicMeta": {
      "type": "object",
      "description": "Response metadata: exactly four fields, and no source.",
      "required": [
        "request_id",
        "fetched_at",
        "cache",
        "version"
      ],
      "properties": {
        "cache": {
          "$ref": "#/$defs/CacheStatus"
        },
        "fetched_at": {
          "type": "string",
          "format": "date-time"
        },
        "request_id": {
          "type": "string",
          "format": "uuid"
        },
        "version": {
          "type": "string"
        }
      }
    },
    "PublicNumber": {
      "type": "number"
    },
    "PublicPageLimit": {
      "type": "integer",
      "format": "int32",
      "description": "The number of history items requested.",
      "minimum": 0
    },
    "PublicRevisionId": {
      "type": "string",
      "format": "uuid",
      "description": "A revision identifier."
    },
    "PublicRevisionReason": {
      "type": "string",
      "description": "Why a revision was recorded.",
      "enum": [
        "baseline",
        "observation_changed",
        "availability_changed",
        "coverage_changed",
        "evidence_changed",
        "participation_changed",
        "completeness_changed",
        "calculation_changed",
        "withdrawal",
        "identity_deferred"
      ]
    },
    "PublicRounding": {
      "type": "string",
      "description": "How a rule rounds.",
      "enum": [
        "finite_f64"
      ]
    },
    "PublicSnapshotNo": {
      "type": "string",
      "description": "A committed snapshot number, as a decimal string."
    },
    "PublicStateReason": {
      "type": "string",
      "description": "Why a state holds.",
      "enum": [
        "reported",
        "confirmed_absence",
        "no_evidence",
        "baseline_unverified",
        "identity_deferred",
        "inputs_missing",
        "expectation_unknown",
        "audit_not_enabled",
        "capability_rule",
        "role_rule",
        "zero_denominator"
      ]
    },
    "PublicUnit": {
      "type": "string",
      "description": "Numeric domain of a value.",
      "enum": [
        "count",
        "flag",
        "dimensionless",
        "minutes",
        "seconds",
        "yards",
        "metres",
        "innings",
        "runs_per_nine_innings",
        "baserunners_per_inning",
        "bases_per_at_bat",
        "yards_per_attempt",
        "yards_per_carry",
        "yards_per_reception",
        "yards_per_punt",
        "rating_points",
        "strokes_per_round",
        "place"
      ]
    },
    "QualifiedMeasure": {
      "type": "string",
      "description": "A registered measure id such as `pitching.hld`."
    },
    "StatContext": {
      "type": "object",
      "description": "The contest, person and team a revision describes.",
      "required": [
        "contest_id",
        "person_id",
        "team_id",
        "competition_id",
        "contest_context"
      ],
      "properties": {
        "competition_id": {
          "$ref": "#/$defs/CompetitionId"
        },
        "contest_context": {
          "$ref": "#/$defs/AuditContestContext"
        },
        "contest_id": {
          "$ref": "#/$defs/ContestId"
        },
        "person_id": {
          "$ref": "#/$defs/PersonId"
        },
        "team_id": {
          "oneOf": [
            {
              "type": "null",
              "description": "Accepts the JSON null value."
            },
            {
              "$ref": "#/$defs/TeamId"
            }
          ]
        }
      }
    },
    "StatDescriptor": {
      "type": "object",
      "description": "Generated name, description and unit of a measure.",
      "required": [
        "id",
        "name",
        "description",
        "unit",
        "calculation"
      ],
      "properties": {
        "calculation": {
          "oneOf": [
            {
              "type": "null",
              "description": "Accepts the JSON null value."
            },
            {
              "$ref": "#/$defs/CalculationMetadata"
            }
          ]
        },
        "description": {
          "type": "string"
        },
        "id": {
          "$ref": "#/$defs/QualifiedMeasure"
        },
        "name": {
          "type": "string"
        },
        "unit": {
          "$ref": "#/$defs/PublicUnit"
        }
      }
    },
    "StatHistory": {
      "type": "object",
      "description": "A page of history, newest first.",
      "required": [
        "status",
        "started_at",
        "before_start",
        "limit",
        "items",
        "next_cursor",
        "has_more"
      ],
      "properties": {
        "before_start": {
          "$ref": "#/$defs/BeforeStart"
        },
        "has_more": {
          "type": "boolean"
        },
        "items": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/StatRevision"
          }
        },
        "limit": {
          "$ref": "#/$defs/PublicPageLimit"
        },
        "next_cursor": {
          "oneOf": [
            {
              "type": "null",
              "description": "Accepts the JSON null value."
            },
            {
              "$ref": "#/$defs/PublicCursor"
            }
          ]
        },
        "started_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "status": {
          "$ref": "#/$defs/HistoryStatus"
        }
      }
    },
    "StatHistoryPage": {
      "type": "object",
      "description": "An older page of one stat's history, fixed to the first page's snapshot.",
      "required": [
        "stat",
        "context",
        "snapshot_no",
        "support",
        "history"
      ],
      "properties": {
        "context": {
          "$ref": "#/$defs/StatContext"
        },
        "history": {
          "$ref": "#/$defs/StatHistory"
        },
        "snapshot_no": {
          "$ref": "#/$defs/PublicSnapshotNo"
        },
        "stat": {
          "$ref": "#/$defs/StatDescriptor"
        },
        "support": {
          "$ref": "#/$defs/AuditSupport"
        }
      }
    },
    "StatRevision": {
      "type": "object",
      "description": "One accepted semantic revision with its frozen context.",
      "required": [
        "revision_id",
        "value",
        "status",
        "state_reason",
        "reason",
        "unit",
        "coverage",
        "calculation",
        "updated_at",
        "last_checked_at",
        "recorded_at",
        "context"
      ],
      "properties": {
        "calculation": {
          "oneOf": [
            {
              "type": "null",
              "description": "Accepts the JSON null value."
            },
            {
              "$ref": "#/$defs/CalculationMetadata"
            }
          ]
        },
        "context": {
          "$ref": "#/$defs/StatContext"
        },
        "coverage": {
          "$ref": "#/$defs/MeasureCoverage"
        },
        "last_checked_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "reason": {
          "$ref": "#/$defs/PublicRevisionReason"
        },
        "recorded_at": {
          "type": "string",
          "format": "date-time"
        },
        "revision_id": {
          "$ref": "#/$defs/PublicRevisionId"
        },
        "state_reason": {
          "$ref": "#/$defs/PublicStateReason"
        },
        "status": {
          "$ref": "#/$defs/PublicAvailability"
        },
        "unit": {
          "$ref": "#/$defs/PublicUnit"
        },
        "updated_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "value": {
          "oneOf": [
            {
              "type": "null",
              "description": "Accepts the JSON null value."
            },
            {
              "$ref": "#/$defs/PublicNumber"
            }
          ]
        }
      }
    },
    "SupportStatus": {
      "type": "string",
      "description": "Audit enablement level.",
      "enum": [
        "enabled",
        "partial",
        "not_enabled"
      ]
    },
    "TeamId": {
      "type": "string",
      "description": "Sport-scoped team id (`team_...`).\nCanonical entity identifier (`team_<base32>`). The suffix is exactly 26 Crockford base32 symbols encoding a UUID. Output uses lowercase without padding. The prefix is case-sensitive; another entity type’s prefix and bare UUID/source identifiers are rejected. Treat the full identifier as opaque."
    }
  }
}