{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:altium-monkey:schema:paint_bindings_c0",
  "type": "object",
  "properties": {
    "schema": {
      "type": "string",
      "const": "altium_monkey.paint_bindings.c0"
    },
    "paint_sha256": {
      "$ref": "#/$defs/Sha256"
    },
    "scope": {
      "$ref": "#/$defs/PaintBindingScope"
    },
    "bindings": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/PaintOccurrenceBinding"
      }
    },
    "issues": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/QueryIssue"
      }
    }
  },
  "required": [
    "schema",
    "paint_sha256",
    "scope",
    "bindings",
    "issues"
  ],
  "unevaluatedProperties": {
    "not": {}
  },
  "$defs": {
    "Sha256": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$",
      "description": "Lowercase SHA-256 digest without a prefix."
    },
    "PaintBindingScope": {
      "type": "object",
      "properties": {
        "instance_path": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Identity"
          }
        },
        "document_path": {
          "type": "string"
        },
        "page_ref": {
          "$ref": "#/$defs/NullableIdentity"
        },
        "page_member": {
          "type": "string"
        }
      },
      "required": [
        "instance_path",
        "document_path",
        "page_ref"
      ],
      "unevaluatedProperties": {
        "not": {}
      },
      "description": "Exported bindings refer to one exact serialized PaintIR artifact."
    },
    "PaintOccurrenceBinding": {
      "type": "object",
      "properties": {
        "occurrence_id": {
          "$ref": "#/$defs/Identity"
        },
        "source_binding_status": {
          "$ref": "#/$defs/SourceBindingStatus",
          "description": "Describes source association, never electrical or freshness coverage."
        },
        "source_keys": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/CompiledSourceKey"
          },
          "description": "Usually one source; aggregate drawing items may map to several."
        },
        "issues": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/LocalIssue"
          }
        }
      },
      "required": [
        "occurrence_id",
        "source_binding_status",
        "source_keys",
        "issues"
      ],
      "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
    },
    "NullableIdentity": {
      "anyOf": [
        {
          "$ref": "#/$defs/Identity"
        },
        {
          "type": "null"
        }
      ]
    },
    "SourceBindingStatus": {
      "anyOf": [
        {
          "type": "string",
          "const": "exact"
        },
        {
          "type": "string",
          "const": "partial"
        },
        {
          "type": "string",
          "const": "unresolved"
        },
        {
          "type": "string",
          "const": "ambiguous"
        },
        {
          "type": "string",
          "const": "not_applicable"
        }
      ]
    },
    "CompiledSourceKey": {
      "anyOf": [
        {
          "$ref": "#/$defs/SchematicSourceKey"
        },
        {
          "$ref": "#/$defs/SystemSourceKey"
        },
        {
          "$ref": "#/$defs/SystemDrawingSourceKey"
        }
      ]
    },
    "LocalIssue": {
      "type": "object",
      "properties": {
        "source_key": {
          "$ref": "#/$defs/CompiledSourceKey"
        },
        "reason": {
          "$ref": "#/$defs/Reason"
        }
      },
      "required": [
        "reason"
      ],
      "unevaluatedProperties": {
        "not": {}
      }
    },
    "SourceOccurrence": {
      "type": "object",
      "properties": {
        "instance_path": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Identity"
          }
        },
        "source_key": {
          "$ref": "#/$defs/CompiledSourceKey"
        }
      },
      "required": [
        "instance_path",
        "source_key"
      ],
      "unevaluatedProperties": {
        "not": {}
      }
    },
    "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."
    },
    "Reason": {
      "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": {}
      }
    },
    "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."
    },
    "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."
    },
    "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": {}
      }
    },
    "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."
    }
  }
}
