{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:altium-monkey:schema:net_explanation_c0",
  "type": "object",
  "properties": {
    "schema": {
      "type": "string",
      "const": "altium_monkey.net_explanation.c0"
    },
    "target": {
      "$ref": "#/$defs/NetOccurrence"
    },
    "primary_name": {
      "$ref": "#/$defs/NullableText",
      "description": "Only a primary actually supplied by the owning electrical definition."
    },
    "system_links": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/LinkExplanation"
      }
    },
    "design_nets": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/ChildNetSummary"
      }
    },
    "fields": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/FieldExplanation"
      }
    },
    "issues": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/QueryIssue"
      }
    }
  },
  "required": [
    "schema",
    "target",
    "primary_name",
    "system_links",
    "design_nets",
    "fields",
    "issues"
  ],
  "unevaluatedProperties": {
    "not": {}
  },
  "$defs": {
    "NetOccurrence": {
      "type": "object",
      "properties": {
        "instance_path": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Identity"
          }
        },
        "net_ref": {
          "$ref": "#/$defs/Identity"
        }
      },
      "required": [
        "instance_path",
        "net_ref"
      ],
      "unevaluatedProperties": {
        "not": {}
      },
      "description": "Query paths traverse composite instances from the loaded root."
    },
    "NullableText": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "LinkExplanation": {
      "type": "object",
      "properties": {
        "source": {
          "$ref": "#/$defs/SourceOccurrence"
        },
        "connection_source": {
          "$ref": "#/$defs/SourceOccurrence"
        },
        "connection_designator": {
          "$ref": "#/$defs/NullableText"
        },
        "defined_name": {
          "$ref": "#/$defs/NullableName"
        },
        "derived_name": {
          "$ref": "#/$defs/NullableName"
        },
        "effective_name": {
          "$ref": "#/$defs/NullableName"
        },
        "endpoints": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/ExplainedLinkEndpoint"
          },
          "minItems": 2,
          "maxItems": 2
        },
        "system_net_binding": {
          "$ref": "#/$defs/QueryNetBinding"
        }
      },
      "required": [
        "source",
        "connection_source",
        "connection_designator",
        "defined_name",
        "derived_name",
        "effective_name",
        "endpoints",
        "system_net_binding"
      ],
      "unevaluatedProperties": {
        "not": {}
      }
    },
    "ChildNetSummary": {
      "type": "object",
      "properties": {
        "target": {
          "$ref": "#/$defs/NetOccurrence"
        },
        "project_path": {
          "type": "string"
        },
        "name": {
          "$ref": "#/$defs/NullableText"
        },
        "naming": {
          "$ref": "#/$defs/NetNamingSummary"
        },
        "naming_complete": {
          "type": "boolean"
        }
      },
      "required": [
        "target",
        "project_path",
        "name",
        "naming",
        "naming_complete"
      ],
      "unevaluatedProperties": {
        "not": {}
      }
    },
    "FieldExplanation": {
      "type": "object",
      "properties": {
        "key": {
          "$ref": "#/$defs/FieldKey"
        },
        "project_path": {
          "type": "string"
        },
        "raw_value": {
          "type": "string"
        },
        "impacts": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/FieldImpact"
          },
          "description": "Every prepared reverse impact, including occurrences outside selected net."
        }
      },
      "required": [
        "key",
        "project_path",
        "raw_value",
        "impacts"
      ],
      "unevaluatedProperties": {
        "not": {}
      }
    },
    "QueryIssue": {
      "type": "object",
      "properties": {
        "source": {
          "$ref": "#/$defs/SourceOccurrence"
        },
        "target": {
          "$ref": "#/$defs/NetOccurrence"
        },
        "page_ref": {
          "$ref": "#/$defs/Identity"
        },
        "reason": {
          "$ref": "#/$defs/Reason"
        }
      },
      "required": [
        "reason"
      ],
      "unevaluatedProperties": {
        "not": {}
      }
    },
    "Identity": {
      "type": "string",
      "minLength": 1
    },
    "SourceOccurrence": {
      "type": "object",
      "properties": {
        "instance_path": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Identity"
          }
        },
        "source_key": {
          "$ref": "#/$defs/CompiledSourceKey"
        }
      },
      "required": [
        "instance_path",
        "source_key"
      ],
      "unevaluatedProperties": {
        "not": {}
      }
    },
    "NullableName": {
      "anyOf": [
        {
          "$ref": "#/$defs/NonemptyName"
        },
        {
          "type": "null"
        }
      ]
    },
    "ExplainedLinkEndpoint": {
      "anyOf": [
        {
          "$ref": "#/$defs/PresentEndpointExplanation"
        },
        {
          "$ref": "#/$defs/NoPinEndpoint"
        },
        {
          "$ref": "#/$defs/UnresolvedEndpoint"
        },
        {
          "$ref": "#/$defs/AmbiguousEndpoint"
        }
      ]
    },
    "QueryNetBinding": {
      "anyOf": [
        {
          "$ref": "#/$defs/ExactQueryNet"
        },
        {
          "$ref": "#/$defs/Unresolved"
        },
        {
          "$ref": "#/$defs/Ambiguous"
        },
        {
          "$ref": "#/$defs/NotApplicable"
        }
      ]
    },
    "NetNamingSummary": {
      "type": "object",
      "properties": {
        "auto_named": {
          "type": "boolean"
        },
        "aliases": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "original_name": {
          "$ref": "#/$defs/NullableText"
        },
        "override_name": {
          "$ref": "#/$defs/NullableText"
        },
        "origin": {
          "$ref": "#/$defs/NamingOrigin"
        }
      },
      "required": [
        "auto_named",
        "aliases",
        "original_name",
        "override_name",
        "origin"
      ],
      "unevaluatedProperties": {
        "not": {}
      },
      "description": "Report facts omit the redundant definition-local net_ref."
    },
    "FieldKey": {
      "type": "object",
      "properties": {
        "definition_ref": {
          "$ref": "#/$defs/Identity"
        },
        "source_key": {
          "$ref": "#/$defs/SchematicSourceKey"
        },
        "field": {
          "$ref": "#/$defs/NameField"
        }
      },
      "required": [
        "definition_ref",
        "source_key",
        "field"
      ],
      "unevaluatedProperties": {
        "not": {}
      }
    },
    "FieldImpact": {
      "type": "object",
      "properties": {
        "target": {
          "$ref": "#/$defs/NetOccurrence"
        },
        "project_path": {
          "type": "string"
        },
        "name": {
          "$ref": "#/$defs/NullableText"
        },
        "page_ref": {
          "$ref": "#/$defs/NullableIdentity"
        },
        "physical_document_key": {
          "type": "string"
        },
        "effective_value": {
          "type": "string"
        },
        "removed": {
          "type": "boolean"
        }
      },
      "required": [
        "target",
        "project_path",
        "name",
        "page_ref",
        "physical_document_key",
        "effective_value",
        "removed"
      ],
      "unevaluatedProperties": {
        "not": {}
      }
    },
    "Reason": {
      "type": "string",
      "minLength": 1
    },
    "CompiledSourceKey": {
      "anyOf": [
        {
          "$ref": "#/$defs/SchematicSourceKey"
        },
        {
          "$ref": "#/$defs/SystemSourceKey"
        },
        {
          "$ref": "#/$defs/SystemDrawingSourceKey"
        }
      ]
    },
    "NonemptyName": {
      "type": "string",
      "minLength": 1
    },
    "PresentEndpointExplanation": {
      "type": "object",
      "properties": {
        "status": {
          "type": "string",
          "const": "present"
        },
        "endpoint": {
          "$ref": "#/$defs/EndpointExplanation"
        }
      },
      "required": [
        "status",
        "endpoint"
      ],
      "unevaluatedProperties": {
        "not": {}
      }
    },
    "NoPinEndpoint": {
      "type": "object",
      "properties": {
        "status": {
          "type": "string",
          "const": "no_pin"
        }
      },
      "required": [
        "status"
      ],
      "unevaluatedProperties": {
        "not": {}
      }
    },
    "UnresolvedEndpoint": {
      "type": "object",
      "properties": {
        "status": {
          "type": "string",
          "const": "unresolved"
        },
        "source_pin_id": {
          "$ref": "#/$defs/NullableNativePinId"
        },
        "reason": {
          "$ref": "#/$defs/Reason"
        }
      },
      "required": [
        "status",
        "source_pin_id",
        "reason"
      ],
      "unevaluatedProperties": {
        "not": {}
      },
      "description": "A missing/null native side is distinct from the persisted NoPin sentinel."
    },
    "AmbiguousEndpoint": {
      "type": "object",
      "properties": {
        "status": {
          "type": "string",
          "const": "ambiguous"
        },
        "source_pin_id": {
          "type": "integer",
          "minimum": -2147483648,
          "maximum": 2147483647
        },
        "reason": {
          "$ref": "#/$defs/Reason"
        }
      },
      "required": [
        "status",
        "source_pin_id",
        "reason"
      ],
      "unevaluatedProperties": {
        "not": {}
      }
    },
    "ExactQueryNet": {
      "type": "object",
      "properties": {
        "status": {
          "type": "string",
          "const": "exact"
        },
        "target": {
          "$ref": "#/$defs/NetOccurrence"
        }
      },
      "required": [
        "status",
        "target"
      ],
      "unevaluatedProperties": {
        "not": {}
      }
    },
    "Unresolved": {
      "type": "object",
      "properties": {
        "status": {
          "type": "string",
          "const": "unresolved"
        },
        "reason": {
          "$ref": "#/$defs/Reason"
        }
      },
      "required": [
        "status",
        "reason"
      ],
      "unevaluatedProperties": {
        "not": {}
      }
    },
    "Ambiguous": {
      "type": "object",
      "properties": {
        "status": {
          "type": "string",
          "const": "ambiguous"
        },
        "reason": {
          "$ref": "#/$defs/Reason"
        }
      },
      "required": [
        "status",
        "reason"
      ],
      "unevaluatedProperties": {
        "not": {}
      }
    },
    "NotApplicable": {
      "type": "object",
      "properties": {
        "status": {
          "type": "string",
          "const": "not_applicable"
        },
        "reason": {
          "$ref": "#/$defs/Reason"
        }
      },
      "required": [
        "status",
        "reason"
      ],
      "unevaluatedProperties": {
        "not": {}
      }
    },
    "NamingOrigin": {
      "anyOf": [
        {
          "$ref": "#/$defs/KnownNamingOrigin"
        },
        {
          "$ref": "#/$defs/UnavailableNamingOrigin"
        }
      ]
    },
    "SchematicSourceKey": {
      "type": "object",
      "properties": {
        "kind": {
          "type": "string",
          "const": "schematic"
        },
        "document_path": {
          "type": "string"
        },
        "locator": {
          "$ref": "#/$defs/OwnedSourceLocator"
        }
      },
      "required": [
        "kind",
        "document_path",
        "locator"
      ],
      "unevaluatedProperties": {
        "not": {}
      }
    },
    "NameField": {
      "anyOf": [
        {
          "type": "string",
          "const": "Name"
        },
        {
          "type": "string",
          "const": "Text"
        }
      ],
      "description": "Authored naming field families. Record-kind checks remain semantic."
    },
    "NullableIdentity": {
      "anyOf": [
        {
          "$ref": "#/$defs/Identity"
        },
        {
          "type": "null"
        }
      ]
    },
    "SystemSourceKey": {
      "type": "object",
      "properties": {
        "kind": {
          "type": "string",
          "const": "system"
        },
        "document_path": {
          "type": "string"
        },
        "object_kind": {
          "$ref": "#/$defs/SystemObjectKind"
        },
        "owner_path": {
          "type": "array",
          "items": {
            "type": "integer",
            "minimum": -2147483648,
            "maximum": 2147483647
          },
          "minItems": 1
        }
      },
      "required": [
        "kind",
        "document_path",
        "object_kind",
        "owner_path"
      ],
      "unevaluatedProperties": {
        "not": {}
      }
    },
    "SystemDrawingSourceKey": {
      "type": "object",
      "properties": {
        "kind": {
          "type": "string",
          "const": "system_drawing"
        },
        "document_path": {
          "type": "string"
        },
        "page_member": {
          "type": "string"
        },
        "item_id": {
          "type": "integer",
          "minimum": -2147483648,
          "maximum": 2147483647
        }
      },
      "required": [
        "kind",
        "document_path",
        "page_member",
        "item_id"
      ],
      "unevaluatedProperties": {
        "not": {}
      },
      "description": "Authored MBS drawing item, distinct from a logical pin or connection."
    },
    "EndpointExplanation": {
      "type": "object",
      "properties": {
        "source": {
          "$ref": "#/$defs/SourceOccurrence"
        },
        "module": {
          "$ref": "#/$defs/NullableText"
        },
        "connector": {
          "$ref": "#/$defs/NullableText"
        },
        "pin_number": {
          "$ref": "#/$defs/NullableText"
        },
        "pin_name": {
          "$ref": "#/$defs/NullableText"
        },
        "snapshot_name": {
          "$ref": "#/$defs/NullableText"
        },
        "resolved_snapshot_name": {
          "$ref": "#/$defs/NullableText"
        },
        "child_binding": {
          "$ref": "#/$defs/QueryTerminalBinding"
        },
        "system_net_binding": {
          "$ref": "#/$defs/QueryNetBinding"
        },
        "child_net": {
          "$ref": "#/$defs/NullableChildNetSummary",
          "description": "Derived from child terminal membership; unavailable when not admitted."
        }
      },
      "required": [
        "source",
        "module",
        "connector",
        "pin_number",
        "pin_name",
        "snapshot_name",
        "resolved_snapshot_name",
        "child_binding",
        "system_net_binding",
        "child_net"
      ],
      "unevaluatedProperties": {
        "not": {}
      }
    },
    "NullableNativePinId": {
      "anyOf": [
        {
          "type": "integer",
          "minimum": -2147483648,
          "maximum": 2147483647
        },
        {
          "type": "null"
        }
      ],
      "description": "Raw native nullable pin side; the NoPin sentinel has its own endpoint kind."
    },
    "KnownNamingOrigin": {
      "type": "object",
      "properties": {
        "status": {
          "type": "string",
          "const": "known"
        },
        "kind": {
          "$ref": "#/$defs/NamingOriginKind",
          "description": "Origin of original_name before any retained override, not auto_named."
        },
        "winning_field": {
          "$ref": "#/$defs/LocalWinningField",
          "description": "Present only when the actual resolver selected this exact source field."
        }
      },
      "required": [
        "status",
        "kind"
      ],
      "unevaluatedProperties": {
        "not": {}
      }
    },
    "UnavailableNamingOrigin": {
      "type": "object",
      "properties": {
        "status": {
          "type": "string",
          "const": "unavailable"
        },
        "reason": {
          "$ref": "#/$defs/Reason"
        }
      },
      "required": [
        "status",
        "reason"
      ],
      "unevaluatedProperties": {
        "not": {}
      }
    },
    "OwnedSourceLocator": {
      "anyOf": [
        {
          "$ref": "#/$defs/PersistedUidLocator"
        },
        {
          "$ref": "#/$defs/SourceOrdinalLocator"
        }
      ]
    },
    "SystemObjectKind": {
      "anyOf": [
        {
          "type": "string",
          "const": "module"
        },
        {
          "type": "string",
          "const": "entry"
        },
        {
          "type": "string",
          "const": "pin"
        },
        {
          "type": "string",
          "const": "connection"
        },
        {
          "type": "string",
          "const": "physical_connection"
        },
        {
          "type": "string",
          "const": "pin_pair"
        }
      ],
      "description": "Native logical kinds already admitted by the System source inventory."
    },
    "QueryTerminalBinding": {
      "anyOf": [
        {
          "$ref": "#/$defs/ExactQueryTerminal"
        },
        {
          "$ref": "#/$defs/Unresolved"
        },
        {
          "$ref": "#/$defs/Ambiguous"
        },
        {
          "$ref": "#/$defs/NotApplicable"
        }
      ]
    },
    "NullableChildNetSummary": {
      "anyOf": [
        {
          "$ref": "#/$defs/ChildNetSummary"
        },
        {
          "type": "null"
        }
      ]
    },
    "NamingOriginKind": {
      "anyOf": [
        {
          "type": "string",
          "const": "authored"
        },
        {
          "type": "string",
          "const": "generated"
        },
        {
          "type": "string",
          "const": "derived"
        }
      ]
    },
    "LocalWinningField": {
      "type": "object",
      "properties": {
        "source_key": {
          "$ref": "#/$defs/SchematicSourceKey"
        },
        "field": {
          "$ref": "#/$defs/NameField"
        }
      },
      "required": [
        "source_key",
        "field"
      ],
      "unevaluatedProperties": {
        "not": {}
      },
      "description": "Exact source field selected by a retained naming decision, not value equality."
    },
    "PersistedUidLocator": {
      "type": "object",
      "properties": {
        "kind": {
          "type": "string",
          "const": "persisted_uid"
        },
        "owner_source_key": {
          "$ref": "#/$defs/NullableSourceKey"
        },
        "record_kind": {
          "$ref": "#/$defs/RecordKind"
        },
        "unique_id": {
          "type": "string"
        }
      },
      "required": [
        "kind",
        "owner_source_key",
        "record_kind",
        "unique_id"
      ],
      "unevaluatedProperties": {
        "not": {}
      }
    },
    "SourceOrdinalLocator": {
      "type": "object",
      "properties": {
        "kind": {
          "type": "string",
          "const": "source_ordinal"
        },
        "owner_source_key": {
          "$ref": "#/$defs/NullableSourceKey"
        },
        "record_kind": {
          "$ref": "#/$defs/RecordKind"
        },
        "source_ordinal": {
          "$ref": "#/$defs/Nat"
        }
      },
      "required": [
        "kind",
        "owner_source_key",
        "record_kind",
        "source_ordinal"
      ],
      "unevaluatedProperties": {
        "not": {}
      }
    },
    "ExactQueryTerminal": {
      "type": "object",
      "properties": {
        "status": {
          "type": "string",
          "const": "exact"
        },
        "target": {
          "$ref": "#/$defs/TerminalOccurrence"
        }
      },
      "required": [
        "status",
        "target"
      ],
      "unevaluatedProperties": {
        "not": {}
      }
    },
    "NullableSourceKey": {
      "anyOf": [
        {
          "$ref": "#/$defs/SourceKey"
        },
        {
          "type": "null"
        }
      ]
    },
    "RecordKind": {
      "anyOf": [
        {
          "type": "string",
          "const": "line"
        },
        {
          "type": "string",
          "const": "rectangle"
        },
        {
          "type": "string",
          "const": "round_rectangle"
        },
        {
          "type": "string",
          "const": "ellipse"
        },
        {
          "type": "string",
          "const": "arc"
        },
        {
          "type": "string",
          "const": "elliptical_arc"
        },
        {
          "type": "string",
          "const": "polygon"
        },
        {
          "type": "string",
          "const": "polyline"
        },
        {
          "type": "string",
          "const": "bezier"
        },
        {
          "type": "string",
          "const": "pie_chart"
        },
        {
          "type": "string",
          "const": "component"
        },
        {
          "type": "string",
          "const": "pin"
        },
        {
          "type": "string",
          "const": "ieee_symbol"
        },
        {
          "type": "string",
          "const": "label"
        },
        {
          "type": "string",
          "const": "parameter"
        },
        {
          "type": "string",
          "const": "designator"
        },
        {
          "type": "string",
          "const": "image"
        },
        {
          "type": "string",
          "const": "note"
        },
        {
          "type": "string",
          "const": "text_frame"
        },
        {
          "type": "string",
          "const": "wire"
        },
        {
          "type": "string",
          "const": "bus"
        },
        {
          "type": "string",
          "const": "bus_entry"
        },
        {
          "type": "string",
          "const": "junction"
        },
        {
          "type": "string",
          "const": "net_label"
        },
        {
          "type": "string",
          "const": "power_port"
        },
        {
          "type": "string",
          "const": "port"
        },
        {
          "type": "string",
          "const": "no_erc"
        },
        {
          "type": "string",
          "const": "sheet_symbol"
        },
        {
          "type": "string",
          "const": "sheet_entry"
        },
        {
          "type": "string",
          "const": "sheet"
        },
        {
          "type": "string",
          "const": "sheet_name"
        },
        {
          "type": "string",
          "const": "file_name"
        },
        {
          "type": "string",
          "const": "implementation_list"
        },
        {
          "type": "string",
          "const": "implementation"
        },
        {
          "type": "string",
          "const": "map_definer"
        },
        {
          "type": "string",
          "const": "harness_connector"
        },
        {
          "type": "string",
          "const": "harness_entry"
        },
        {
          "type": "string",
          "const": "harness_type"
        },
        {
          "type": "string",
          "const": "signal_harness"
        },
        {
          "type": "string",
          "const": "harness_splice"
        },
        {
          "type": "string",
          "const": "harness_layout_label"
        },
        {
          "type": "string",
          "const": "harness_layout_connection_point"
        },
        {
          "type": "string",
          "const": "harness_bundle"
        },
        {
          "type": "string",
          "const": "harness_covering"
        },
        {
          "type": "string",
          "const": "template"
        },
        {
          "type": "string",
          "const": "parameter_set"
        },
        {
          "type": "string",
          "const": "compile_mask"
        },
        {
          "type": "string",
          "const": "blanket"
        },
        {
          "type": "string",
          "const": "hyperlink"
        },
        {
          "type": "string",
          "const": "file_header"
        },
        {
          "type": "string",
          "const": "map_definer_list"
        },
        {
          "type": "string",
          "const": "impl_params"
        }
      ]
    },
    "Nat": {
      "type": "integer",
      "minimum": 0,
      "maximum": 9007199254740991,
      "description": "JSON-safe nonnegative integer."
    },
    "TerminalOccurrence": {
      "type": "object",
      "properties": {
        "instance_path": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Identity"
          }
        },
        "terminal_ref": {
          "$ref": "#/$defs/Identity"
        }
      },
      "required": [
        "instance_path",
        "terminal_ref"
      ],
      "unevaluatedProperties": {
        "not": {}
      }
    },
    "SourceKey": {
      "type": "string",
      "pattern": "^source:sha256:[0-9a-f]{64}$",
      "description": "Document-scoped source identity digest."
    }
  }
}
