{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://igrm.in/schemas/knowledge-replay-ledger.schema.json",
  "title": "IGRM signed knowledge-replay ledger",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "object_type",
    "schema_version",
    "ledger_id",
    "record_sha256",
    "created_at",
    "replay_registry_sha256",
    "availability_signers_sha256",
    "ledger_signer_id",
    "ledger_signature_path",
    "entries",
    "counts"
  ],
  "properties": {
    "object_type": {"const": "knowledge_replay_ledger"},
    "schema_version": {"const": "1.0.0"},
    "ledger_id": {"type": "string", "pattern": "^kld:[a-z0-9][a-z0-9._:-]{2,123}$"},
    "record_sha256": {"$ref": "common.schema.json#/$defs/sha256"},
    "created_at": {"$ref": "common.schema.json#/$defs/utcDateTime"},
    "replay_registry_sha256": {"$ref": "common.schema.json#/$defs/sha256"},
    "availability_signers_sha256": {"$ref": "common.schema.json#/$defs/sha256"},
    "ledger_signer_id": {"$ref": "common.schema.json#/$defs/stableId"},
    "ledger_signature_path": {
      "type": "string",
      "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))(?!.*\\\\).+\\.sig$"
    },
    "entries": {
      "type": "array",
      "minItems": 1,
      "items": {"$ref": "#/$defs/releaseEntry"}
    },
    "counts": {
      "type": "object",
      "additionalProperties": false,
      "required": ["releases"],
      "properties": {"releases": {"type": "integer", "minimum": 1}}
    }
  },
  "$defs": {
    "safeJsonPath": {
      "type": "string",
      "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))(?!.*\\\\).+\\.json$"
    },
    "governanceFile": {
      "type": "object",
      "additionalProperties": false,
      "required": ["path", "sha256"],
      "properties": {
        "path": {"$ref": "#/$defs/safeJsonPath"},
        "sha256": {"$ref": "common.schema.json#/$defs/sha256"}
      }
    },
    "governanceSnapshot": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "canonical_schema_registry",
        "canonical_method_registry",
        "source_rights_registry",
        "rights_signers",
        "release_signers"
      ],
      "properties": {
        "canonical_schema_registry": {"$ref": "#/$defs/governanceFile"},
        "canonical_method_registry": {"$ref": "#/$defs/governanceFile"},
        "source_rights_registry": {"$ref": "#/$defs/governanceFile"},
        "rights_signers": {"$ref": "#/$defs/governanceFile"},
        "release_signers": {"$ref": "#/$defs/governanceFile"}
      }
    },
    "releaseEntry": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "sequence",
        "snapshot_kind",
        "release_id",
        "manifest_path",
        "manifest_file_sha256",
        "manifest_record_sha256",
        "generated_at",
        "effective_date",
        "available_at",
        "receipt_path",
        "receipt_file_sha256",
        "governance"
      ],
      "properties": {
        "sequence": {"type": "integer", "minimum": 1},
        "snapshot_kind": {"const": "complete"},
        "release_id": {"$ref": "common.schema.json#/$defs/stableId"},
        "manifest_path": {"$ref": "#/$defs/safeJsonPath"},
        "manifest_file_sha256": {"$ref": "common.schema.json#/$defs/sha256"},
        "manifest_record_sha256": {"$ref": "common.schema.json#/$defs/sha256"},
        "generated_at": {"$ref": "common.schema.json#/$defs/utcDateTime"},
        "effective_date": {"$ref": "common.schema.json#/$defs/date"},
        "available_at": {"$ref": "common.schema.json#/$defs/utcDateTime"},
        "receipt_path": {"$ref": "#/$defs/safeJsonPath"},
        "receipt_file_sha256": {"$ref": "common.schema.json#/$defs/sha256"},
        "governance": {"$ref": "#/$defs/governanceSnapshot"}
      }
    }
  }
}
