{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schemas.helloorigo.com/chronicle/integrity-evidence-export-v2.schema.json",
  "title": "Chronicle v2 per-entry chain export view",
  "type": "object",
  "additionalProperties": false,
  "required": ["chainId", "entries"],
  "properties": {
    "chainId": { "$ref": "#/$defs/uuid" },
    "entries": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/entry" } }
  },
  "$defs": {
    "uuid": { "type": "string", "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$" },
    "sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
    "entry": {
      "type": "object", "additionalProperties": false,
      "required": ["chainSeq", "id", "commitmentVersion", "contentCommitment", "prevHash", "entryHash", "materialStatus"],
      "properties": {
        "chainSeq": { "type": "integer", "minimum": 1 },
        "id": { "$ref": "#/$defs/uuid" },
        "commitmentVersion": { "enum": [1, 2] },
        "contentCommitment": { "$ref": "#/$defs/sha256" },
        "prevHash": { "$ref": "#/$defs/sha256" },
        "entryHash": { "$ref": "#/$defs/sha256" },
        "materialStatus": { "enum": ["included", "elided", "erased"] },
        "source": { "$ref": "source-record-v2.schema.json" }
      },
      "allOf": [
        { "if": { "properties": { "materialStatus": { "const": "included" } }, "required": ["materialStatus"] },
          "then": { "required": ["source"], "properties": { "commitmentVersion": { "const": 2 } } },
          "else": { "not": { "required": ["source"] } } }
      ]
    }
  }
}
