{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://openaudiovisual.com/packages/devices/device.schema.json",
  "title": "Open Audiovisual device record",
  "description": "The outer record every device in the open-audiovisual collection has: what it is, how it plugs in, where its deeper data lives (a MIDI profile, a DMX fixture, a part of the electronics library) or its facts with the page each one was read from, how to set it up, what goes wrong, how OAV reaches it, and how sure the record is. validateDevice() in @openav/devices (packages/devices/record.js) is stricter: every citation must point at a source that exists, a camera or an audio interface needs media, Chinese text must not use the full-width semicolon or the dash, and verified: true needs a verification with method hardware.",
  "type": "object",
  "required": ["format", "id", "kind", "manufacturer", "name", "aliases", "connections", "protocols", "data", "setup", "problems", "use", "sources", "license", "verified", "verifications"],
  "additionalProperties": false,
  "properties": {
    "format": { "const": "open-audiovisual/device@1" },
    "id": { "$ref": "#/$defs/id" },
    "kind": { "enum": ["midi-controller", "dmx-fixture", "dmx-interface", "led-controller", "sensor", "camera", "audio-interface", "projector", "display", "printer", "part"] },
    "manufacturer": { "type": ["string", "null"], "minLength": 1, "description": "null when the file the record is read from names no maker" },
    "name": { "type": "string", "minLength": 1, "description": "the name people know it by, maker included where they say it" },
    "aliases": { "type": "array", "items": { "type": "string", "minLength": 1 }, "description": "what people type when they search for it" },
    "connections": {
      "type": "array",
      "uniqueItems": true,
      "items": { "enum": ["usb", "din-midi", "trs-midi", "ethernet", "wifi", "bluetooth", "hdmi", "displayport", "sdi", "dmx-xlr3", "dmx-xlr5", "audio-xlr", "audio-jack"] }
    },
    "protocols": { "type": "array", "items": { "type": "string", "pattern": "^[a-z0-9][a-z0-9.+-]*$" } },
    "data": {
      "type": "object",
      "minProperties": 1,
      "additionalProperties": false,
      "properties": {
        "ref": {
          "type": "object",
          "required": ["type", "id", "file"],
          "additionalProperties": false,
          "properties": {
            "type": { "enum": ["midi-profile", "dmx-fixture", "hw-part"] },
            "id": { "$ref": "#/$defs/id" },
            "file": { "type": "string", "minLength": 1, "description": "the file the deeper record lives in, as a path inside packages/" }
          }
        },
        "facts": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": ["key", "value", "source"],
            "additionalProperties": false,
            "properties": {
              "key": { "type": "string", "pattern": "^[a-z][A-Za-z0-9]*$" },
              "value": { "type": ["string", "number", "boolean", "array", "object"] },
              "unit": { "type": "string", "minLength": 1 },
              "note": { "type": "string" },
              "source": { "$ref": "#/$defs/cite" }
            }
          }
        }
      }
    },
    "media": {
      "type": "object",
      "description": "a camera or an audio interface: how a browser finds it among the media devices, and what to ask it for",
      "required": ["input", "labels", "constraints", "sources"],
      "additionalProperties": false,
      "properties": {
        "input": { "enum": ["videoinput", "audioinput"] },
        "labels": { "type": "array", "minItems": 1, "items": { "type": "string", "minLength": 1 }, "description": "regular expressions (case-insensitive) matched against MediaDeviceInfo.label" },
        "constraints": { "type": "object", "description": "videoinput: { width, height, fps } as ideal values; audioinput: MediaTrackConstraints" },
        "sources": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/cite" } }
      }
    },
    "setup": { "type": "array", "items": { "$ref": "#/$defs/step" } },
    "problems": { "type": "array", "items": { "$ref": "#/$defs/step" } },
    "use": {
      "type": ["array", "null"],
      "minItems": 1,
      "description": "how OAV reaches the device today; null when it does not",
      "items": {
        "type": "object",
        "required": ["package", "entry", "call", "en", "zh"],
        "additionalProperties": false,
        "properties": {
          "package": { "type": "string", "pattern": "^@openav/[a-z0-9-]+$" },
          "entry": { "type": "string", "minLength": 1, "description": "the export it starts from" },
          "sink": { "type": "string", "description": "the out-bridge sink, when the path goes through the bridge" },
          "call": { "type": "string", "minLength": 1 },
          "en": { "type": "string", "minLength": 1 },
          "zh": { "type": "string", "minLength": 1 }
        }
      }
    },
    "sources": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["title"],
        "additionalProperties": false,
        "properties": {
          "title": { "type": "string", "minLength": 1 },
          "url": { "type": "string", "pattern": "^https?://" },
          "read": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$", "description": "the day the page was read" },
          "note": { "type": "string" },
          "license": { "type": "string" }
        }
      }
    },
    "license": { "type": "string", "minLength": 1, "description": "SPDX id of this record's data, such as MIT" },
    "verified": { "type": "boolean", "description": "true only with a verification made on the unit itself (method hardware)" },
    "verifications": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["date", "by", "method"],
        "properties": {
          "date": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$" },
          "by": { "type": "string", "minLength": 1 },
          "method": { "enum": ["hardware", "virtual", "simulated"] },
          "firmware": { "type": "string" },
          "os": { "type": "string" },
          "browser": { "type": "string" },
          "note": { "type": "string" }
        }
      }
    },
    "notes": { "type": "array", "items": { "$ref": "#/$defs/text" } },
    "tbd": { "type": "array", "items": { "$ref": "#/$defs/text" }, "description": "what could not be confirmed: never a guess" }
  },
  "$defs": {
    "id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9_-]*$" },
    "cite": { "type": "integer", "minimum": 0, "description": "an index into sources" },
    "text": {
      "type": "object",
      "required": ["en", "zh"],
      "additionalProperties": false,
      "properties": { "en": { "type": "string", "minLength": 1 }, "zh": { "type": "string", "minLength": 1 } }
    },
    "step": {
      "type": "object",
      "required": ["en", "zh", "source"],
      "additionalProperties": false,
      "properties": { "en": { "type": "string", "minLength": 1 }, "zh": { "type": "string", "minLength": 1 }, "source": { "$ref": "#/$defs/cite" } }
    }
  }
}
