{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:cede:schema:monitoring-webhook-index:v0",
  "title": "CEDE monitoring webhook index, v0",
  "description": "The body of GET /monitoring/{id}/webhooks — every address this account has registered on one monitoring record, each carrying its own delivery log (SPEC.md section 3.6). Each entry is a whole registration: the same document POST /monitoring/{id}/webhooks answers with, and monitoring-webhook.v0.schema.json is the authority on its shape. This schema states the members an entry must carry rather than restating that one in full, because two schemas describing the same bytes drift and then disagree about which is right; the contract suite validates every entry here against monitoring-webhook.v0 as well, so the two are held together by a test rather than by a copy. Everything monitoring-webhook.v0 says applies to every entry: a delivery is the difference between two readings of an index computed by analytics software, never a notice under any contract, and no amount of money appears in one.",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema_version", "monitoring_id", "count", "webhooks", "links"],
  "properties": {
    "schema_version": { "type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$" },
    "monitoring_id": { "type": "string", "minLength": 1 },
    "count": { "type": "integer", "minimum": 0, "description": "How many registrations this record carries. Equal to the length of `webhooks`: this build pages nothing, and a count that could differ from the list would be a promise of paging that does not exist." },
    "webhooks": {
      "type": "array",
      "description": "The registrations, oldest first. Another account's are not here and are not counted.",
      "items": {
        "type": "object",
        "additionalProperties": true,
        "required": [
          "schema_version",
          "id",
          "monitoring_id",
          "structure_id",
          "url",
          "status",
          "registered_at",
          "triggers",
          "measurement",
          "delivery",
          "notifications",
          "delivery_log",
          "disclosure"
        ],
        "properties": {
          "schema_version": { "type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$" },
          "id": { "type": "string", "minLength": 1 },
          "monitoring_id": { "type": "string", "minLength": 1 },
          "structure_id": { "type": "string", "minLength": 1 },
          "url": { "type": "string", "minLength": 1 },
          "status": { "type": "string", "enum": ["registered"] },
          "registered_at": { "type": "string", "minLength": 20 },
          "triggers": { "type": "object", "required": ["compared_fields", "basis", "evaluated_on"] },
          "measurement": {
            "type": "object",
            "additionalProperties": true,
            "description": "The four compared fields the registration currently stands on, the unit they are read in, and the label of the model that produced them — restated here so a reader of the list alone can rely on them and can attribute the level, exactly as a reader of one registration can (SPEC.md section 4, P9).",
            "required": ["feed_id", "vintage", "index_value", "index_unit", "distance_to_attachment", "model"],
            "properties": {
              "feed_id": { "type": "string", "minLength": 1 },
              "model": {
                "type": "object",
                "additionalProperties": true,
                "required": ["name", "version"],
                "description": "The model and version that computed this level. Required on a list entry as on a registration: a level served without it is an unattributed number.",
                "properties": {
                  "name": { "type": "string", "minLength": 1 },
                  "version": { "type": "string", "minLength": 1 }
                }
              },
              "vintage": { "type": "string", "minLength": 1 },
              "index_value": { "type": ["number", "null"] },
              "index_unit": { "type": "string", "minLength": 1 },
              "distance_to_attachment": { "type": ["number", "null"] }
            }
          },
          "delivery": {
            "type": "object",
            "additionalProperties": true,
            "required": ["guarantee", "maximum_attempts", "timeout_seconds", "basis"],
            "properties": {
              "guarantee": { "type": "string", "enum": ["at_least_once"] },
              "maximum_attempts": { "type": "integer", "minimum": 1 },
              "timeout_seconds": { "type": "number", "exclusiveMinimum": 0 },
              "basis": { "type": "string", "minLength": 1 }
            }
          },
          "notifications": { "type": "array" },
          "delivery_log": { "type": "array" },
          "disclosure": { "type": "string", "minLength": 1 }
        }
      }
    },
    "links": {
      "type": "object",
      "additionalProperties": false,
      "required": ["self", "monitoring"],
      "properties": {
        "self": { "type": "string", "minLength": 1 },
        "monitoring": { "type": "string", "minLength": 1 }
      }
    }
  }
}
