{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:altium-monkey:schema:structural_graph_c0",
  "type": "object",
  "properties": {
    "schema": {
      "type": "string",
      "const": "altium_monkey.structural_graph.c0"
    },
    "root_definition_ref": {
      "$ref": "#/$defs/StructuralIdentity"
    },
    "definitions": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/StructuralDefinition"
      }
    },
    "gaps": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Projection gaps and native diagnostic context; a partial view remains useful."
    }
  },
  "required": [
    "schema",
    "root_definition_ref",
    "definitions",
    "gaps"
  ],
  "unevaluatedProperties": {
    "not": {}
  },
  "description": "Checked electrical membership, independent of source CAD and drawing data.\nThis does not replace Design B0's BOM, variants or placement carrier.",
  "title": "Altium Monkey shared structural graph c0",
  "$defs": {
    "StructuralIdentity": {
      "type": "string",
      "minLength": 1,
      "description": "Definition-local opaque nonempty identity. Names and source paths are not refs."
    },
    "StructuralDefinition": {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/StructuralIdentity"
        },
        "instances": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/StructuralInstance"
          }
        },
        "terminals": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/StructuralTerminal"
          }
        },
        "nets": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/StructuralNet"
          }
        },
        "net_bridges": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/NetBridge"
          },
          "description": "One row per bridge component of this definition, in instance order."
        },
        "bridged_groups": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/BridgedNetGroup"
          },
          "description": "Derived from net_bridges; a System closure has none of its own."
        }
      },
      "required": [
        "id",
        "instances",
        "terminals",
        "nets",
        "net_bridges",
        "bridged_groups"
      ],
      "unevaluatedProperties": {
        "not": {}
      },
      "description": "Same shape for a compiled Design or composed System."
    },
    "StructuralInstance": {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/StructuralIdentity"
        },
        "definition_ref": {
          "$ref": "#/$defs/StructuralIdentity"
        }
      },
      "required": [
        "id"
      ],
      "unevaluatedProperties": {
        "not": {}
      },
      "description": "A physical component (no definition_ref), or one composed child occurrence."
    },
    "StructuralTerminal": {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/StructuralIdentity"
        },
        "instance_ref": {
          "$ref": "#/$defs/StructuralIdentity"
        }
      },
      "required": [
        "id"
      ],
      "unevaluatedProperties": {
        "not": {}
      },
      "description": "Physical pin identity; instance_ref identifies its physical component."
    },
    "StructuralNet": {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/StructuralIdentity"
        },
        "name": {
          "type": "string",
          "description": "Compiled primary name when one exists. System closure has no primary."
        },
        "members": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/StructuralMember"
          }
        }
      },
      "required": [
        "id",
        "members"
      ],
      "unevaluatedProperties": {
        "not": {}
      }
    },
    "NetBridge": {
      "type": "object",
      "properties": {
        "instance_ref": {
          "$ref": "#/$defs/StructuralIdentity"
        },
        "designator": {
          "type": "string"
        },
        "kind": {
          "$ref": "#/$defs/NetBridgeKind"
        },
        "pins": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/NetBridgePin"
          }
        },
        "net_refs": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/StructuralIdentity"
          },
          "description": "The distinct nets of its pins, in net order."
        }
      },
      "required": [
        "instance_ref",
        "designator",
        "kind",
        "pins",
        "net_refs"
      ],
      "unevaluatedProperties": {
        "not": {}
      },
      "description": "A component that deliberately joins nets on the board, such as a net tie.\nThe joined nets stay separate nets: this records the intended short only.\nAt schematic level a bridge covers all its pins (all its terminals, in\nterminal order). Which pads its board copper actually joins, island by\nisland, is a board fact this graph does not hold."
    },
    "BridgedNetGroup": {
      "type": "object",
      "properties": {
        "net_refs": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/StructuralIdentity"
          },
          "minItems": 2,
          "description": "In net order."
        },
        "bridge_refs": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/StructuralIdentity"
          },
          "minItems": 1,
          "description": "The bridges joining these nets, in bridge order."
        },
        "designators": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "The designators of bridge_refs, in the same order."
        }
      },
      "required": [
        "net_refs",
        "bridge_refs",
        "designators"
      ],
      "unevaluatedProperties": {
        "not": {}
      },
      "description": "Nets joined by bridges, transitively, with the bridges that join them.\nOnly groups of two or more nets are listed, in order of their first net."
    },
    "StructuralMember": {
      "anyOf": [
        {
          "$ref": "#/$defs/StructuralTerminalMember"
        },
        {
          "$ref": "#/$defs/StructuralChildNetMember"
        }
      ]
    },
    "NetBridgeKind": {
      "anyOf": [
        {
          "type": "string",
          "const": "net_tie_bom"
        },
        {
          "type": "string",
          "const": "net_tie_no_bom"
        }
      ],
      "description": "Component kinds that bridge nets: Altium Net Tie, In BOM (kind 3) or No BOM (kind 4)."
    },
    "NetBridgePin": {
      "type": "object",
      "properties": {
        "terminal_ref": {
          "$ref": "#/$defs/StructuralIdentity"
        },
        "hardware_designation": {
          "type": "string",
          "description": "Pin designation, for reading; terminal_ref is the identity."
        },
        "net_ref": {
          "$ref": "#/$defs/StructuralIdentity"
        }
      },
      "required": [
        "terminal_ref",
        "hardware_designation"
      ],
      "unevaluatedProperties": {
        "not": {}
      },
      "description": "One pin of a bridge component; net_ref is absent when the pin is on no net."
    },
    "StructuralTerminalMember": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "const": "terminal"
        },
        "terminal_ref": {
          "$ref": "#/$defs/StructuralIdentity"
        }
      },
      "required": [
        "type",
        "terminal_ref"
      ],
      "unevaluatedProperties": {
        "not": {}
      },
      "description": "Membership is stored once, at its owning definition."
    },
    "StructuralChildNetMember": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "const": "child_net"
        },
        "instance_ref": {
          "$ref": "#/$defs/StructuralIdentity"
        },
        "net_ref": {
          "$ref": "#/$defs/StructuralIdentity"
        }
      },
      "required": [
        "type",
        "instance_ref",
        "net_ref"
      ],
      "unevaluatedProperties": {
        "not": {}
      },
      "description": "Immediate child binding. Deep instance paths are derived by traversal."
    }
  }
}
