{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://breadkit.github.io/breadkit/schema/part-v1.json",
  "title": "Breadkit part definition v1",
  "type": "object",
  "required": ["id", "pins"],
  "properties": {
    "id": { "type": "string", "minLength": 1 },
    "datasheet_url": { "type": "string", "format": "uri", "pattern": "^https://" },
    "aliases": { "type": "array", "items": { "type": "string", "minLength": 1 } },
    "category": { "type": "string" },
    "extends": { "type": "string" },
    "override": { "type": "boolean" },
    "straddle": { "type": "boolean" },
    "transistor_polarity": { "enum": ["NPN", "PNP"] },
    "flags": { "type": "array", "items": { "type": "string" } },
    "supply_range": { "type": "array", "prefixItems": [{ "type": "number" }, { "type": "number" }], "minItems": 2, "maxItems": 2 },
    "max_reverse_voltage": { "type": "number", "minimum": 0 },
    "forward_voltage": { "type": "number", "exclusiveMinimum": 0 },
    "on_resistance": { "type": "number", "exclusiveMinimum": 0 },
    "max_forward_current": { "type": "number", "exclusiveMinimum": 0 },
    "max_lead_span_mm": { "type": "number", "exclusiveMinimum": 0 },
    "package": { "type": "object", "properties": { "pins": { "type": "integer", "minimum": 1 } }, "additionalProperties": false },
    "attributes": { "type": "object", "additionalProperties": { "oneOf": [{ "const": "css_color" }, { "type": "array", "minItems": 1, "items": { "type": ["string", "number"] } }] } },
    "required_attributes": { "type": "array", "uniqueItems": true, "items": { "type": "string" } },
    "provides": {
      "type": "array",
      "items": { "type": "object", "required": ["positive", "negative", "voltage"],
        "properties": { "positive": { "type": "string" }, "negative": { "type": "string" }, "voltage": { "type": "number", "exclusiveMinimum": 0 },
          "voltage_range": { "type": "array", "prefixItems": [{ "type": "number", "exclusiveMinimum": 0 }, { "type": "number", "exclusiveMinimum": 0 }], "minItems": 2, "maxItems": 2 },
          "when": { "type": "object", "minProperties": 1, "additionalProperties": { "type": ["string", "number"] } } },
        "additionalProperties": false }
    },
    "render": {
      "type": "object",
      "properties": {
        "shape": { "type": "string" }, "label": { "type": "string" },
        "size_mm": { "type": "array", "prefixItems": [{ "type": "number" }, { "type": "number" }], "minItems": 2, "maxItems": 2 },
        "body_offset_mm": { "type": "array", "prefixItems": [{ "type": "number" }, { "type": "number" }], "minItems": 2, "maxItems": 2 },
        "fill": { "type": "string" }, "stroke": { "type": "string" }, "text_color": { "type": "string" },
        "svg": { "type": "string" }
      }, "additionalProperties": false
    },
    "placement": { "enum": ["leads", "dip", "footprint", "offboard"] },
    "pins": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["num"],
        "properties": {
          "num": { "type": ["integer", "string"] },
          "name": { "type": "string" },
          "aliases": { "type": "array", "items": { "type": "string" } },
          "type": { "$ref": "#/$defs/pinRole" },
          "role": { "$ref": "#/$defs/pinRole" },
          "label": { "type": ["boolean", "string"] },
          "max_voltage": { "type": "number", "exclusiveMinimum": 0 },
          "max_current": { "type": "number", "exclusiveMinimum": 0 },
          "output_capable": { "type": "boolean" },
          "mount": { "const": "rail" }
        },
        "not": { "required": ["type", "role"] },
        "additionalProperties": false
      }
    },
    "polarity": { "type": "object", "additionalProperties": { "type": ["string", "integer"] } },
    "footprint": {
      "type": "object",
      "additionalProperties": {
        "type": "array", "prefixItems": [{ "type": "integer" }, { "type": "integer" }],
        "minItems": 2, "maxItems": 2
      }
    },
    "footprint_mm": {
      "type": "object",
      "additionalProperties": {
        "type": "array", "prefixItems": [{ "type": "number" }, { "type": "number" }],
        "minItems": 2, "maxItems": 2
      }
    },
    "internal": { "$ref": "#/$defs/pairs" },
    "switch": { "$ref": "#/$defs/pairs" },
    "independent_switches": { "const": true },
    "same_strip_ok": { "$ref": "#/$defs/pairs" }
  },
  "additionalProperties": false,
  "$defs": {
    "pinRole": { "enum": ["input", "output", "gpio", "power", "ground", "data", "clock", "interrupt", "address", "nc", "passive", "analog", "reset", "open_drain"] },
    "pairs": {
      "type": "array",
      "items": {
        "type": "array", "prefixItems": [{ "type": ["string", "integer"] }, { "type": ["string", "integer"] }],
        "minItems": 2, "maxItems": 2
      }
    }
  }
}
