{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/peppolstatus-com/json-schema/peppolstatus-com-event-feed-page-schema.json",
  "title": "EventFeedPage",
  "description": "A cursor page of change events with a prev cursor and first-page meta.",
  "x-generated": "2026-11-21",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/peppolstatus-com-events-api-openapi.yml#/components/schemas/EventFeedPage",
  "type": "object",
  "required": [
    "items",
    "next_cursor",
    "prev_cursor"
  ],
  "properties": {
    "items": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/GlobalEvent"
      }
    },
    "next_cursor": {
      "type": [
        "string",
        "null"
      ]
    },
    "prev_cursor": {
      "type": [
        "string",
        "null"
      ],
      "description": "Newer-direction cursor (newest row on the page); the live-mode watermark."
    },
    "meta": {
      "$ref": "#/$defs/EventFeedMeta"
    }
  },
  "$defs": {
    "AnomalyRef": {
      "type": "object",
      "required": [
        "id",
        "detector",
        "grade"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "detector": {
          "type": "string",
          "enum": [
            "cert_identity_shift",
            "off_cadence_rotation",
            "endpoint_off_footprint",
            "moved_to_unverified_seat",
            "mass_change_burst",
            "split_id_registration",
            "host_tls_cert_expired",
            "host_tls_cert_expiring"
          ]
        },
        "grade": {
          "type": "string",
          "enum": [
            "notice",
            "warning",
            "info"
          ]
        }
      }
    },
    "EventChartBucket": {
      "type": "object",
      "required": [
        "bucket_start",
        "count"
      ],
      "properties": {
        "bucket_start": {
          "type": "string",
          "format": "date-time"
        },
        "count": {
          "type": "integer"
        }
      }
    },
    "EventFeedMeta": {
      "type": "object",
      "description": "First-page events metadata: exact type facets + filter count (the events table is small enough for exact aggregation), an estimated total, and an auto-bucketed timeline chart over the (filtered) window.",
      "required": [
        "total_count",
        "total_count_estimated",
        "filter_count",
        "facets",
        "chart_bucket",
        "chart_data"
      ],
      "properties": {
        "total_count": {
          "type": "integer",
          "description": "Estimated total (pg_class.reltuples)."
        },
        "total_count_estimated": {
          "type": "boolean"
        },
        "filter_count": {
          "type": [
            "integer",
            "null"
          ],
          "description": "Exact count matching active filters, or null when none is active."
        },
        "facets": {
          "type": "object",
          "description": "Exact per-type counts under the non-type filters.",
          "additionalProperties": {
            "type": "array",
            "items": {
              "$ref": "#/$defs/FacetBucket"
            }
          }
        },
        "chart_bucket": {
          "type": "string",
          "enum": [
            "hour",
            "day",
            "week"
          ]
        },
        "chart_data": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/EventChartBucket"
          }
        }
      }
    },
    "FacetBucket": {
      "type": "object",
      "required": [
        "value",
        "count"
      ],
      "properties": {
        "value": {
          "type": "string"
        },
        "count": {
          "type": "integer"
        },
        "label": {
          "type": "string",
          "description": "Human-facing label when `value` is an opaque key: the `ap` facet's value is a SeatID and the label the curated provider name; the `size` and `region` facets carry the size band label and the local-language region name of their code (the code itself when it is unknown). Filter on `value`."
        }
      }
    },
    "GlobalEvent": {
      "type": "object",
      "required": [
        "id",
        "type",
        "hostname",
        "observed_at",
        "payload",
        "anomalies"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "type": {
          "type": "string",
          "enum": [
            "participant_registered",
            "participant_deregistered",
            "participant_smp_changed",
            "endpoint_changed",
            "doctype_support_changed",
            "ap_seat_changed",
            "host_cert_rotated",
            "hosting_changed",
            "directory_card_changed"
          ]
        },
        "hostname": {
          "type": [
            "string",
            "null"
          ]
        },
        "observed_at": {
          "type": "string",
          "format": "date-time"
        },
        "payload": {
          "type": "object",
          "additionalProperties": true,
          "description": "Type-specific change detail. An `endpoint_changed` event is one row per real (from, to, transportProfile) change and lists the affected document types in a `doctypes` array; rows written before the merge carry a singular `doctype`."
        },
        "anomalies": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/AnomalyRef"
          }
        }
      }
    }
  }
}