{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "dd-flow/plan-aspect-map@3",
  "type": "object",
  "additionalProperties": false,
  "required": ["$schema", "schema_id", "protocol_id", "plan_id", "plan_revision", "catalog_ref", "routing", "review_groups", "aspects"],
  "properties": {
    "$schema": {"type": "string", "minLength": 1},
    "schema_id": {"const": "dd-flow/plan-aspect-map@3"},
    "protocol_id": {"type": "string", "pattern": "^PRT-"},
    "plan_id": {"type": "string", "minLength": 1},
    "plan_revision": {"type": "integer", "minimum": 1},
    "catalog_ref": {"type": "object", "additionalProperties": false, "required": ["path"], "properties": {"path": {"type": "string", "minLength": 1}, "sha256": {"type": "string", "pattern": "^[a-f0-9]{64}$"}}},
    "routing": {"type": "object", "additionalProperties": false, "required": ["initial_state", "selected_route", "reason", "groups"], "properties": {"initial_state": {"const": "orchestrator_local"}, "selected_route": {"enum": ["local_compact", "single_wave_grouped", "multi_wave_grouped", "external_handoff"]}, "reason": {"type": "string", "minLength": 1}, "groups": {"type": "array", "items": {"$ref": "#/$defs/group"}}}},
    "review_groups": {"type": "array", "description": "Every applicable aspect exactly once. Prefer one semantically safe wave within measured capacity.", "items": {"$ref": "#/$defs/group"}},
    "review_tail_reason": {"type": "string", "minLength": 1},
    "aspects": {"type": "array", "minItems": 1, "items": {"type": "object", "additionalProperties": false, "required": ["aspect_id", "applicability", "reason", "planned_artifact_refs"], "properties": {"aspect_id": {"type": "string", "minLength": 1}, "applicability": {"enum": ["applicable", "not_applicable"]}, "reason": {"type": "string", "minLength": 1}, "planned_artifact_refs": {"type": "array", "items": {"type": "string", "minLength": 1}}}}}
  },
  "$defs": {
    "group": {"type": "object", "additionalProperties": false, "required": ["id", "aspect_ids"], "properties": {"id": {"type": "string", "minLength": 1}, "aspect_ids": {"type": "array", "minItems": 1, "maxItems": 3, "uniqueItems": true, "items": {"type": "string", "minLength": 1}}}}
  }
}
