{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "kicad_cruncher.design_review_manifest.b0",
  "title": "KiCad Cruncher Design Review Manifest",
  "description": "Design B0 review artifact index; source-specific evidence is separate from the canonical electrical and schematic authorities.",
  "type": "object",
  "required": [
    "schema",
    "input",
    "design_json",
    "compiled_schematic_graph",
    "netlist_json",
    "netlist_kicad_sexpr",
    "schematic_svgs",
    "pcb_svgs",
    "readme",
    "source_design_json"
  ],
  "properties": {
    "schema": {
      "const": "kicad_cruncher.design_review_manifest.b0"
    },
    "input": {
      "type": "string",
      "minLength": 1
    },
    "design_json": {
      "$ref": "#/$defs/artifact_path"
    },
    "compiled_schematic_graph": {
      "$ref": "#/$defs/compiled_schematic_graph"
    },
    "netlist_json": {
      "$ref": "#/$defs/artifact_path"
    },
    "netlist_kicad_sexpr": {
      "$ref": "#/$defs/artifact_path"
    },
    "schematic_svgs": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/schematic_svg"
      }
    },
    "pcb_svgs": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/pcb_svg"
      }
    },
    "readme": {
      "$ref": "#/$defs/artifact_path"
    },
    "design_facts": {
      "$ref": "#/$defs/design_facts"
    },
    "source_design_json": {
      "$ref": "#/$defs/artifact_path"
    }
  },
  "additionalProperties": false,
  "$defs": {
    "artifact_path": {
      "type": "string",
      "minLength": 1,
      "pattern": "^(?![A-Za-z]:)(?!/)(?!.*\\\\)(?!.*(?:^|/)\\.\\.?(?:/|$))[^/]+(?:/[^/]+)*$",
      "description": "Forward-slash path relative to the bundle root."
    },
    "lower_sha256": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$"
    },
    "compiled_schematic_graph": {
      "type": "object",
      "required": [
        "file",
        "schema",
        "type",
        "counts",
        "linkage_contract",
        "version",
        "netlist_ref"
      ],
      "properties": {
        "file": {
          "$ref": "#/$defs/artifact_path"
        },
        "schema": {
          "const": "urn:dm:schema:sch.compiled_schematic_graph.b0"
        },
        "type": {
          "const": "sch.compiled_schematic_graph"
        },
        "counts": {
          "type": "object",
          "required": [
            "unit_definitions",
            "page_definitions",
            "unit_occurrences",
            "page_occurrences",
            "hierarchy_occurrences",
            "bodies",
            "contacts",
            "local_islands",
            "hierarchy_contact_bindings",
            "fields",
            "source_bindings",
            "naming_gaps"
          ],
          "properties": {
            "unit_definitions": {
              "type": "integer",
              "minimum": 0
            },
            "page_definitions": {
              "type": "integer",
              "minimum": 0
            },
            "unit_occurrences": {
              "type": "integer",
              "minimum": 0
            },
            "page_occurrences": {
              "type": "integer",
              "minimum": 0
            },
            "hierarchy_occurrences": {
              "type": "integer",
              "minimum": 0
            },
            "bodies": {
              "type": "integer",
              "minimum": 0
            },
            "contacts": {
              "type": "integer",
              "minimum": 0
            },
            "local_islands": {
              "type": "integer",
              "minimum": 0
            },
            "hierarchy_contact_bindings": {
              "type": "integer",
              "minimum": 0
            },
            "fields": {
              "type": "integer",
              "minimum": 0
            },
            "source_bindings": {
              "type": "integer",
              "minimum": 0
            },
            "naming_gaps": {
              "type": "integer",
              "minimum": 0
            }
          },
          "additionalProperties": false
        },
        "linkage_contract": {
          "const": "sch.graphical_bindings.b0"
        },
        "version": {
          "const": "b0"
        },
        "netlist_ref": {
          "type": "string",
          "minLength": 1
        }
      },
      "additionalProperties": false
    },
    "schematic_svg": {
      "type": "object",
      "required": [
        "file",
        "sheet_number",
        "sheet_count",
        "sheet_name",
        "sheet_path",
        "sheet_path_uuids",
        "sheet_instance_path",
        "source",
        "page_occurrence_ref",
        "artifact_key",
        "graph_link_count",
        "resolved_svg_identity_count",
        "drawing",
        "coverage_issue_count"
      ],
      "properties": {
        "file": {
          "$ref": "#/$defs/artifact_path"
        },
        "sheet_number": {
          "type": "integer",
          "minimum": 1
        },
        "sheet_count": {
          "type": "integer",
          "minimum": 1
        },
        "sheet_name": {
          "type": "string"
        },
        "sheet_path": {
          "type": "string",
          "minLength": 1
        },
        "sheet_path_uuids": {
          "type": "string",
          "minLength": 1
        },
        "sheet_instance_path": {
          "type": "string",
          "minLength": 1
        },
        "source": {
          "type": "string"
        },
        "page_occurrence_ref": {
          "type": "string",
          "minLength": 1
        },
        "artifact_key": {
          "type": "string",
          "minLength": 1
        },
        "graph_link_count": {
          "type": "integer",
          "minimum": 0
        },
        "resolved_svg_identity_count": {
          "type": "integer",
          "minimum": 0
        },
        "drawing": {
          "$ref": "#/$defs/artifact_path"
        },
        "coverage_issue_count": {
          "type": "integer",
          "minimum": 0
        }
      },
      "additionalProperties": false
    },
    "pcb_svg": {
      "type": "object",
      "required": [
        "file",
        "layer",
        "included_layers",
        "drill_slot_record_count"
      ],
      "properties": {
        "file": {
          "$ref": "#/$defs/artifact_path"
        },
        "layer": {
          "type": "string",
          "minLength": 1
        },
        "included_layers": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "drill_slot_record_count": {
          "type": "integer",
          "minimum": 0
        }
      },
      "additionalProperties": false
    },
    "design_facts": {
      "type": "object",
      "required": [
        "backend",
        "engine_version",
        "resource_profile",
        "source_snapshot_sha256",
        "compiled_schematic_graph_sha256",
        "kicad_netlist_bytes",
        "kicad_netlist_sha256"
      ],
      "properties": {
        "backend": {
          "const": "kicad-monkey-native"
        },
        "engine_version": {
          "type": "string",
          "minLength": 1
        },
        "resource_profile": {
          "const": "design-review-b0"
        },
        "source_snapshot_sha256": {
          "$ref": "#/$defs/lower_sha256"
        },
        "compiled_schematic_graph_sha256": {
          "$ref": "#/$defs/lower_sha256"
        },
        "kicad_netlist_bytes": {
          "type": "integer",
          "minimum": 1
        },
        "kicad_netlist_sha256": {
          "$ref": "#/$defs/lower_sha256"
        }
      },
      "additionalProperties": false
    }
  }
}
