{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:okf:uk-legislation:schema:rich-relationship-route-locator-bucket:v1",
  "title": "OKF rich relationship route locator bucket v1",
  "type": "object",
  "required": [
    "schema",
    "generated_at",
    "hash_algorithm",
    "bucket",
    "routes",
    "counts"
  ],
  "properties": {
    "schema": {"const": "okf-rich-relationship-route-locator-bucket.v1"},
    "generated_at": {"type": "string", "format": "date-time"},
    "hash_algorithm": {"const": "sha256-utf8-first-byte-hex"},
    "bucket": {"type": "string", "pattern": "^[0-9a-f]{2}$"},
    "routes": {
      "type": "array",
      "minItems": 1,
      "items": {"$ref": "#/$defs/route"}
    },
    "counts": {
      "type": "object",
      "required": [
        "routes",
        "chunk_references",
        "plane_commitments",
        "incident_assertions",
        "active_incident_assertions"
      ],
      "additionalProperties": {"type": "integer", "minimum": 0}
    }
  },
  "additionalProperties": false,
  "$defs": {
    "safePath": {
      "type": "string",
      "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))[^\\\\]+$"
    },
    "sha256": {"type": "string", "pattern": "^[0-9a-f]{64}$"},
    "plane": {
      "type": "object",
      "required": ["name", "assertions", "assertion_ids_sha256", "chunks"],
      "properties": {
        "name": {"type": "string", "minLength": 1},
        "assertions": {"type": "integer", "minimum": 1},
        "assertion_ids_sha256": {"$ref": "#/$defs/sha256"},
        "chunks": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {"$ref": "#/$defs/safePath"}
        }
      },
      "additionalProperties": false
    },
    "route": {
      "type": "object",
      "required": ["route", "chunks", "planes", "counts"],
      "properties": {
        "route": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9-]*(?:/[A-Za-z0-9._~-]+)+$"
        },
        "chunks": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {"$ref": "#/$defs/safePath"}
        },
        "planes": {
          "type": "array",
          "minItems": 1,
          "items": {"$ref": "#/$defs/plane"}
        },
        "counts": {
          "type": "object",
          "required": [
            "planes",
            "incident_assertions",
            "active_incident_assertions",
            "chunk_references",
            "active_chunk_references"
          ],
          "additionalProperties": {"type": "integer", "minimum": 0}
        }
      },
      "additionalProperties": false
    }
  }
}
