{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "notarius.source.chunk_map",
  "title": "notarius_source_chunk_map_v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "source_id",
    "source_digest",
    "plan_digest",
    "requested_chunker",
    "producer",
    "plan_annotations",
    "chunks"
  ],
  "properties": {
    "source_id": {"type": "string", "minLength": 1},
    "source_digest": {"type": "string", "pattern": "^sha256:[0-9a-f]{64}$"},
    "plan_digest": {"type": "string", "pattern": "^sha256:[0-9a-f]{64}$"},
    "requested_chunker": {"type": "string", "minLength": 1},
    "producer": {
      "type": "object",
      "additionalProperties": false,
      "required": ["input_module", "chunk_module"],
      "properties": {
        "input_module": {"type": "string", "minLength": 1},
        "chunk_module": {"type": "string", "minLength": 1},
        "llm_profile": {"type": "string", "minLength": 1}
      }
    },
    "plan_annotations": {"$ref": "#/$defs/annotations"},
    "chunks": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "index", "source_ref", "unit_count", "annotations"],
        "properties": {
          "id": {"type": "string", "minLength": 1},
          "index": {"type": "integer", "minimum": 0},
          "source_ref": {
            "type": "object",
            "additionalProperties": false,
            "required": ["source_id", "start_unit_id", "end_unit_id"],
            "properties": {
              "source_id": {"type": "string", "minLength": 1},
              "start_unit_id": {"type": "integer", "minimum": 1},
              "end_unit_id": {"type": "integer", "minimum": 1}
            }
          },
          "unit_count": {"type": "integer", "minimum": 1},
          "annotations": {"$ref": "#/$defs/annotations"}
        }
      }
    }
  },
  "$defs": {
    "annotations": {
      "type": "object",
      "propertyNames": {"type": "string", "minLength": 1},
      "additionalProperties": true
    }
  }
}
