{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Latin prose review history v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema",
    "id",
    "created",
    "language",
    "versions",
    "records",
    "activeVersionId",
    "activeRecordId",
    "sha256"
  ],
  "properties": {
    "schema": {
      "const": "magalia.clausulae.prose-review/1"
    },
    "id": {
      "type": "string",
      "minLength": 1
    },
    "created": {
      "type": "string",
      "format": "date-time"
    },
    "language": {
      "const": "lat"
    },
    "versions": {
      "type": "array",
      "minItems": 1,
      "maxItems": 50,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "parentId",
          "source",
          "editEvidence"
        ],
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "parentId": {
            "type": [
              "string",
              "null"
            ]
          },
          "source": {
            "type": "object",
            "required": [
              "documentId",
              "text",
              "language",
              "sha256"
            ],
            "properties": {
              "language": {
                "const": "lat"
              },
              "text": {
                "type": "string",
                "minLength": 1
              },
              "sha256": {
                "type": "string",
                "pattern": "^[a-f0-9]{64}$"
              }
            }
          },
          "editEvidence": {
            "oneOf": [
              {
                "type": "null"
              },
              {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "reviewer",
                  "reason",
                  "source",
                  "location"
                ],
                "properties": {
                  "reviewer": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 2000
                  },
                  "reason": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 2000
                  },
                  "source": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 2000
                  },
                  "location": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 2000
                  }
                }
              }
            ]
          }
        }
      }
    },
    "records": {
      "type": "array",
      "minItems": 1,
      "maxItems": 200,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "versionId",
          "parentId",
          "annotation"
        ],
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "versionId": {
            "type": "string",
            "minLength": 1
          },
          "parentId": {
            "type": [
              "string",
              "null"
            ]
          },
          "annotation": {
            "oneOf": [
              {
                "$ref": "annotation.schema.json"
              },
              {
                "$ref": "automatic-annotation.schema.json"
              },
              {
                "$ref": "review-annotation.schema.json"
              }
            ]
          }
        }
      }
    },
    "activeVersionId": {
      "type": "string",
      "minLength": 1
    },
    "activeRecordId": {
      "type": [
        "string",
        "null"
      ]
    },
    "sha256": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$"
    }
  },
  "$comment": "Runtime checks enforce immutable source hashes, exact lineage, active pointers and reproducible annotation results. History is a new document format, not a rewrite of old annotations."
}
