{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "notarius.source.evidence_context",
  "title": "notarius_source_evidence_context_v1",
  "type": "object",
  "additionalProperties": false,
  "required": ["source_id", "source_digest", "window_units", "selected_lanes", "contexts"],
  "properties": {
    "source_id": {"type": "string", "minLength": 1},
    "source_digest": {"type": "string", "pattern": "^sha256:[0-9a-f]{64}$"},
    "window_units": {"type": "integer", "minimum": 0},
    "selected_lanes": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {"type": "string", "minLength": 1}
    },
    "contexts": {
      "type": "array",
      "items": {"$ref": "#/$defs/context"}
    }
  },
  "$defs": {
    "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": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "kind", "text", "ref"],
      "properties": {
        "id": {"type": "integer", "minimum": 1},
        "kind": {"type": "string", "minLength": 1},
        "text": {"type": "string", "minLength": 1},
        "ref": {"$ref": "#/$defs/source_ref"},
        "metadata": {"type": "object", "additionalProperties": true}
      }
    },
    "evidence_ref": {
      "type": "object",
      "additionalProperties": false,
      "required": ["lane_id", "source_ref"],
      "properties": {
        "lane_id": {"type": "string", "minLength": 1},
        "source_ref": {"$ref": "#/$defs/source_ref"}
      }
    },
    "context": {
      "type": "object",
      "additionalProperties": false,
      "required": ["context_ref", "evidence_refs", "units"],
      "properties": {
        "context_ref": {"$ref": "#/$defs/source_ref"},
        "evidence_refs": {"type": "array", "minItems": 1, "items": {"$ref": "#/$defs/evidence_ref"}},
        "units": {"type": "array", "minItems": 1, "items": {"$ref": "#/$defs/unit"}}
      }
    }
  }
}
