{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:altium-monkey:schema:compiled_schematic_graph_b0",
  "type": "object",
  "properties": {
    "schema": {
      "type": "string",
      "const": "altium_monkey.compiled_schematic_graph.b0"
    },
    "pages": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/PageOccurrence"
      }
    },
    "fields": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/AuthoredField"
      }
    },
    "source_bindings": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/SourceBinding"
      },
      "description": "Pin/body/wire/junction associations, only when source evidence is admitted."
    },
    "naming_gaps": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/NamingGap"
      }
    },
    "issues": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/LocalIssue"
      }
    }
  },
  "required": [
    "schema",
    "pages",
    "fields",
    "source_bindings",
    "naming_gaps",
    "issues"
  ],
  "unevaluatedProperties": {
    "not": {}
  },
  "$defs": {
    "PageOccurrence": {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/Identity"
        },
        "document_path": {
          "type": "string"
        },
        "physical_document_key": {
          "type": "string"
        }
      },
      "required": [
        "id",
        "document_path",
        "physical_document_key"
      ],
      "unevaluatedProperties": {
        "not": {}
      }
    },
    "AuthoredField": {
      "type": "object",
      "properties": {
        "source_key": {
          "$ref": "#/$defs/SchematicSourceKey"
        },
        "field": {
          "$ref": "#/$defs/NameField"
        },
        "raw_value": {
          "type": "string"
        },
        "contexts": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/FieldContext"
          }
        }
      },
      "required": [
        "source_key",
        "field",
        "raw_value",
        "contexts"
      ],
      "unevaluatedProperties": {
        "not": {}
      }
    },
    "SourceBinding": {
      "type": "object",
      "properties": {
        "source_key": {
          "$ref": "#/$defs/SchematicSourceKey"
        },
        "page_ref": {
          "$ref": "#/$defs/NullableIdentity"
        },
        "physical_document_key": {
          "type": "string"
        },
        "targets": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/LocalElectricalTarget"
          }
        },
        "issues": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/LocalIssue"
          }
        }
      },
      "required": [
        "source_key",
        "page_ref",
        "physical_document_key",
        "targets",
        "issues"
      ],
      "unevaluatedProperties": {
        "not": {}
      },
      "description": "Only non-field associations: field object net associations derive from contexts."
    },
    "NamingGap": {
      "type": "object",
      "properties": {
        "net_ref": {
          "$ref": "#/$defs/NullableIdentity"
        },
        "source_key": {
          "$ref": "#/$defs/SchematicSourceKey"
        },
        "reason": {
          "$ref": "#/$defs/Reason"
        }
      },
      "required": [
        "net_ref",
        "reason"
      ],
      "unevaluatedProperties": {
        "not": {}
      },
      "description": "Null target means an unscoped naming gap in this owning Design definition."
    },
    "LocalIssue": {
      "type": "object",
      "properties": {
        "source_key": {
          "$ref": "#/$defs/CompiledSourceKey"
        },
        "reason": {
          "$ref": "#/$defs/Reason"
        }
      },
      "required": [
        "reason"
      ],
      "unevaluatedProperties": {
        "not": {}
      }
    },
    "Identity": {
      "type": "string",
      "minLength": 1
    },
    "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."
    },
    "FieldContext": {
      "type": "object",
      "properties": {
        "page_ref": {
          "$ref": "#/$defs/NullableIdentity"
        },
        "physical_document_key": {
          "type": "string"
        },
        "net_ref": {
          "$ref": "#/$defs/Identity"
        },
        "effective_value": {
          "type": "string"
        },
        "removed": {
          "type": "boolean"
        }
      },
      "required": [
        "page_ref",
        "physical_document_key",
        "net_ref",
        "effective_value",
        "removed"
      ],
      "unevaluatedProperties": {
        "not": {}
      }
    },
    "NullableIdentity": {
      "anyOf": [
        {
          "$ref": "#/$defs/Identity"
        },
        {
          "type": "null"
        }
      ]
    },
    "LocalElectricalTarget": {
      "anyOf": [
        {
          "$ref": "#/$defs/LocalNetTarget"
        },
        {
          "$ref": "#/$defs/LocalTerminalTarget"
        },
        {
          "$ref": "#/$defs/LocalInstanceTarget"
        }
      ]
    },
    "Reason": {
      "type": "string",
      "minLength": 1
    },
    "CompiledSourceKey": {
      "anyOf": [
        {
          "$ref": "#/$defs/SchematicSourceKey"
        },
        {
          "$ref": "#/$defs/SystemSourceKey"
        },
        {
          "$ref": "#/$defs/SystemDrawingSourceKey"
        }
      ]
    },
    "OwnedSourceLocator": {
      "anyOf": [
        {
          "$ref": "#/$defs/PersistedUidLocator"
        },
        {
          "$ref": "#/$defs/SourceOrdinalLocator"
        }
      ]
    },
    "LocalNetTarget": {
      "type": "object",
      "properties": {
        "kind": {
          "type": "string",
          "const": "net"
        },
        "net_ref": {
          "$ref": "#/$defs/Identity"
        }
      },
      "required": [
        "kind",
        "net_ref"
      ],
      "unevaluatedProperties": {
        "not": {}
      }
    },
    "LocalTerminalTarget": {
      "type": "object",
      "properties": {
        "kind": {
          "type": "string",
          "const": "terminal"
        },
        "terminal_ref": {
          "$ref": "#/$defs/Identity"
        }
      },
      "required": [
        "kind",
        "terminal_ref"
      ],
      "unevaluatedProperties": {
        "not": {}
      }
    },
    "LocalInstanceTarget": {
      "type": "object",
      "properties": {
        "kind": {
          "type": "string",
          "const": "instance"
        },
        "instance_ref": {
          "$ref": "#/$defs/Identity"
        }
      },
      "required": [
        "kind",
        "instance_ref"
      ],
      "unevaluatedProperties": {
        "not": {}
      }
    },
    "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."
    },
    "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": {}
      }
    },
    "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."
    },
    "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."
    },
    "SourceKey": {
      "type": "string",
      "pattern": "^source:sha256:[0-9a-f]{64}$",
      "description": "Document-scoped source identity digest."
    }
  }
}
