{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/tipoLi5890/akcli/schemas/diff.schema.json",
  "title": "AkcliDiff",
  "description": "akcli diff --json: net-membership + component diff of two schematic revisions. Nets are matched by pin membership (never by name); components by UniqueID, then signature, then refdes — 'method'/'confidence' say which. Consumers must tolerate additive growth.",
  "type": "object",
  "required": ["schema_version", "summary", "component_changes", "net_changes"],
  "properties": {
    "schema_version": {"type": "string"},
    "summary": {
      "type": "object",
      "required": ["components", "nets", "low_confidence"],
      "properties": {
        "components": {
          "type": "object",
          "required": ["added", "removed", "changed", "matched"],
          "properties": {
            "added": {"type": "integer", "minimum": 0},
            "removed": {"type": "integer", "minimum": 0},
            "changed": {"type": "integer", "minimum": 0},
            "matched": {"type": "integer", "minimum": 0}
          }
        },
        "nets": {
          "type": "object",
          "required": ["added", "removed", "renamed", "membership_changed", "matched"],
          "properties": {
            "added": {"type": "integer", "minimum": 0},
            "removed": {"type": "integer", "minimum": 0},
            "renamed": {"type": "integer", "minimum": 0},
            "membership_changed": {"type": "integer", "minimum": 0},
            "matched": {"type": "integer", "minimum": 0}
          }
        },
        "low_confidence": {"type": "boolean"}
      }
    },
    "low_confidence": {"type": "boolean"},
    "notes": {"type": "array", "items": {"type": "string"}},
    "rename_map": {
      "type": "object",
      "additionalProperties": {"type": "string"}
    },
    "component_changes": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["method", "confidence", "field_changes"],
        "properties": {
          "designator_a": {"type": ["string", "null"]},
          "designator_b": {"type": ["string", "null"]},
          "method": {
            "type": "string",
            "enum": ["unique_id", "signature", "refdes", "added", "removed"]
          },
          "confidence": {"type": "number", "minimum": 0, "maximum": 1},
          "field_changes": {
            "type": "object",
            "additionalProperties": {
              "type": "array", "minItems": 2, "maxItems": 2
            }
          }
        }
      }
    },
    "net_changes": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["method", "membership_changed", "name_changed"],
        "properties": {
          "name_a": {"type": ["string", "null"]},
          "name_b": {"type": ["string", "null"]},
          "stable_id_a": {"type": ["string", "null"]},
          "stable_id_b": {"type": ["string", "null"]},
          "method": {
            "type": "string",
            "enum": ["membership", "added", "removed"]
          },
          "jaccard": {"type": "number", "minimum": 0, "maximum": 1},
          "added_members": {
            "type": "array",
            "items": {"type": "string", "pattern": "^.+\\..+$"}
          },
          "removed_members": {
            "type": "array",
            "items": {"type": "string", "pattern": "^.+\\..+$"}
          },
          "name_changed": {"type": "boolean"},
          "membership_changed": {"type": "boolean"},
          "confidence": {"type": "number", "minimum": 0, "maximum": 1}
        }
      }
    }
  }
}
