{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.switchboard.audio/schemas/object-type.json",
  "title": "Switchboard Object Type",
  "description": "Static type descriptor on a Switchboard object.",
  "type": "object",
  "required": ["type", "subtype", "description"],
  "additionalProperties": false,
  "properties": {
    "type": {
      "description": "The kind of Switchboard object.",
      "type": "string",
      "enum": ["switchboard", "engine", "graph", "node", "extension"]
    },
    "subtype": {
      "description": "Identifies the specific variant within the kind.",
      "type": "string",
      "minLength": 1
    },
    "description": {
      "description": "Human-readable description of the object.",
      "type": "string"
    },
    "displayName": {
      "description": "Display label for UIs. Falls back to subtype when absent.",
      "type": "string"
    },
    "categories": {
      "description": "Tags used to group related objects in UIs.",
      "type": "array",
      "items": { "type": "string" },
      "uniqueItems": true
    },
    "configuration": {
      "description": "Per-parameter construction-time schema, keyed by parameter name.",
      "type": "object",
      "additionalProperties": { "$ref": "#/$defs/configurationEntry" }
    },
    "properties": {
      "description": "Per-property runtime schema, keyed by property name.",
      "type": "object",
      "additionalProperties": { "$ref": "#/$defs/propertyEntry" }
    },
    "actions": {
      "description": "Per-action schema, keyed by action name.",
      "type": "object",
      "additionalProperties": { "$ref": "#/$defs/actionEntry" }
    },
    "events": {
      "description": "Per-event schema, keyed by event name.",
      "type": "object",
      "additionalProperties": { "$ref": "#/$defs/eventEntry" }
    }
  },
  "$defs": {
    "valueType": {
      "type": "string",
      "enum": ["boolean", "float", "int", "string", "array", "object"]
    },
    "configurationEntry": {
      "type": "object",
      "required": ["description", "type", "default"],
      "additionalProperties": false,
      "properties": {
        "name": {
          "type": "string",
          "description": "Inferred from the surrounding map key when omitted."
        },
        "description": { "type": "string" },
        "type": { "$ref": "#/$defs/valueType" },
        "default": { "description": "Default value used when the caller omits this parameter. Must match `type`." },
        "min": { "type": "number" },
        "max": { "type": "number" },
        "options": {
          "type": "array",
          "description": "Allowed values. Each entry must match `type`."
        }
      }
    },
    "propertyEntry": {
      "type": "object",
      "required": ["description", "type", "readOnly"],
      "additionalProperties": false,
      "properties": {
        "name": {
          "type": "string",
          "description": "Inferred from the surrounding map key when omitted."
        },
        "description": { "type": "string" },
        "type": { "$ref": "#/$defs/valueType" },
        "readOnly": { "type": "boolean" },
        "default": {
          "description": "Initial value before the caller sets one. Must match `type`. Only meaningful when `readOnly` is `false`."
        },
        "min": { "type": "number" },
        "max": { "type": "number" },
        "options": {
          "type": "array",
          "description": "Allowed values. Each entry must match `type`."
        },
        "unit": {
          "type": "string",
          "enum": ["ms", "dB", "%", "Hz", "semitones", "BPM", "samples", "frames", "channels", "bytes", "bits"]
        }
      }
    },
    "actionEntry": {
      "type": "object",
      "required": ["description"],
      "additionalProperties": false,
      "properties": {
        "name": {
          "type": "string",
          "description": "Inferred from the surrounding map key when omitted."
        },
        "description": { "type": "string" },
        "parameters": {
          "type": "object",
          "additionalProperties": { "$ref": "#/$defs/actionParameterEntry" }
        }
      }
    },
    "actionParameterEntry": {
      "type": "object",
      "required": ["description", "type"],
      "additionalProperties": false,
      "properties": {
        "name": {
          "type": "string",
          "description": "Inferred from the surrounding map key when omitted."
        },
        "description": { "type": "string" },
        "type": { "$ref": "#/$defs/valueType" },
        "isOptional": {
          "type": "boolean",
          "description": "Defaults to false when omitted."
        }
      }
    },
    "eventEntry": {
      "type": "object",
      "required": ["description"],
      "additionalProperties": false,
      "properties": {
        "name": {
          "type": "string",
          "description": "Inferred from the surrounding map key when omitted."
        },
        "description": { "type": "string" },
        "data": {
          "type": "object",
          "additionalProperties": { "$ref": "#/$defs/eventDataFieldEntry" }
        }
      }
    },
    "eventDataFieldEntry": {
      "type": "object",
      "required": ["description", "type"],
      "additionalProperties": false,
      "properties": {
        "name": {
          "type": "string",
          "description": "Inferred from the surrounding map key when omitted."
        },
        "description": { "type": "string" },
        "type": { "$ref": "#/$defs/valueType" }
      }
    }
  }
}
