{
  "type": "object",
  "patternProperties": {
    "^.*$": {
      "$ref": "#/definitions/capability"
    }
  },
  "additionalProperties": false,
  "definitions": {
    "capability": {
      "type": "object",
      "properties": {
        "title": {
          "$ref": "#/definitions/i18n"
        },
        "description": {
          "$ref": "#/definitions/i18n"
        },
        "icon": {
          "type": "string",
          "pattern": "^[a-z][a-zA-Z0-9]*$"
        },
        "state": {
          "type": "object",
          "additionalProperties": false,
          "patternProperties": {
            "^.*$": {
              "$ref": "#/definitions/state"
            }
          }
        },
        "ui": {
          "$ref": "#/definitions/ui"
        },
        "status": {
          "type": "object",
          "additionalProperties": false,
          "patternProperties": {
            "^.*$": {
              "$ref": "#/definitions/state"
            }
          }
        }
      },
      "additionalProperties": false,
      "required": ["title"]
    },
    "state": {
      "type": "object",
      "properties": {
        "title": {
          "$ref": "#/definitions/i18n"
        },
        "description": {
          "$ref": "#/definitions/i18n"
        },
        "type": {
          "type": "string",
          "enum": [
            "enum",
            "boolean",
            "number",
            "string",
            "object",
            "object[]",
            "boolean[]",
            "number[]",
            "string[]"
          ]
        },
        "enum": {
          "type": "array",
          "uniqueItems": true,
          "additionalItems": false,
          "items": {
            "oneOf": [
              {
                "type": "string",
                "minLength": 1
              },
              {
                "type": "number"
              }
            ]
          }
        },
        "gettable": {
          "type": "boolean"
        },
        "settable": {
          "type": "boolean"
        },
        "required": {
          "type": "boolean"
        },
        "decimals": {
          "type": "number",
          "minimum": 0,
          "maximum": 8
        },
        "minimum": {
          "type": "number"
        },
        "maximum": {
          "type": "number"
        },
        "step": {
          "type": "number",
          "minimum": 0
        },
        "unit": {
          "$ref": "#/definitions/i18n"
        },
        "properties": {
          "type": "object",
          "additionalProperties": false,
          "patternProperties": {
            "^.*$": {
              "$ref": "#/definitions/state"
            }
          }
        },
        "ui": {
          "$ref": "#/definitions/ui"
        }
      },
      "additionalProperties": false,
      "if": {
        "properties": {
          "type": {
            "const": "enum"
          }
        }
      },
      "then": {
        "required": ["enum"]
      },
      "required": ["gettable", "settable"]
    },
    "i18n": {
      "type": "object",
      "required": ["en"],
      "patternProperties": {
        "^.*$": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "ui": {
      "type": "object",
      "description": "Presentation hints. Capability-level keys (primary, category, size) describe the whole capability; field-level keys (control, format, scale, labels, severity) describe a single state field; 'hidden' applies at either level.",
      "properties": {
        "hidden": {
          "type": "boolean",
          "description": "Hide this capability or field from generic UIs."
        },
        "primary": {
          "type": "string",
          "description": "Capability-level: key of the state field that best represents this capability in compact views."
        },
        "category": {
          "type": "string",
          "description": "Capability-level: semantic grouping for sectioning and default styling.",
          "enum": [
            "sensor",
            "control",
            "alarm",
            "status",
            "media",
            "connectivity",
            "power",
            "info"
          ]
        },
        "control": {
          "type": "string",
          "description": "Field-level: explicit input/display control. 'auto' lets the UI derive it from type/settable/range.",
          "enum": [
            "auto",
            "toggle",
            "slider",
            "stepper",
            "number",
            "text",
            "select",
            "readonly",
            "button"
          ]
        },
        "format": {
          "type": "string",
          "description": "Field-level: how to format the value. Disambiguates values that share a raw type/unit (e.g. an epoch 'datetime' vs a 'duration', both ms numbers).",
          "enum": [
            "number",
            "datetime",
            "duration",
            "hex",
            "percent",
            "bytes",
            "phone"
          ]
        },
        "scale": {
          "type": "number",
          "description": "Field-level: multiply the raw value by this factor for display (e.g. 0..1 -> 0..100 with scale 100)."
        },
        "labels": {
          "type": "object",
          "description": "Field-level: map of value -> localized label. For booleans use keys 'true'/'false'; for enums use the enum values.",
          "patternProperties": {
            "^.*$": {
              "$ref": "#/definitions/i18n"
            }
          },
          "additionalProperties": false
        },
        "severity": {
          "type": "string",
          "description": "Field-level: affect of the active/abnormal value, for coloring (e.g. an alarm boolean).",
          "enum": ["neutral", "info", "success", "warning", "alarm"]
        }
      },
      "additionalProperties": false
    }
  }
}
