{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Alarm (DTC) list response",
  "description": "Schema for the /api/dtcs response envelope as produced by dtc_list_as_json",
  "type": "object",
  "properties": {
    "type": {
      "type": "string",
      "const": "dtcs",
      "description": "Message type discriminator"
    },
    "dtcs": {
      "type": "array",
      "description": "List of active and muted alarms",
      "items": { "$ref": "#/definitions/alarm" }
    },
    "active": {
      "type": "integer",
      "description": "Count of alarms that are not muted by a filter"
    },
    "muted": {
      "type": "integer",
      "description": "Count of alarms that are muted by a filter"
    }
  },
  "required": ["type", "dtcs", "active", "muted"],
  "definitions": {
    "alarm": {
      "type": "object",
      "description": "A single alarm/DTC event",
      "properties": {
        "alarmCode": {
          "type": "integer",
          "description": "The numeric code identifying the specific alarm"
        },
        "alarmDescription": {
          "type": "string",
          "description": "Human-readable description of the alarm. Sourced from the DTC database; set to 'unknown' when the code is not found in the database"
        },
        "alarmDescription.FR": {
          "type": "string",
          "description": "French translation of the alarm description. Only present when supplied by the DTC database entry"
        },
        "severity": {
          "type": "string",
          "description": "Severity level of the alarm. Sourced from the DTC database; set to 'unknown' when the code is not found. Typical values: 'warning', 'error', 'unknown'"
        },
        "deviceId": {
          "type": "integer",
          "description": "The device ID that raised the alarm"
        },
        "functionCode": {
          "type": "integer",
          "description": "Function code extracted from deviceId"
        },
        "functionName": {
          "type": "string",
          "description": "Human-readable function name corresponding to functionCode, in English. 'Unknown' for a code with no name"
        },
        "instance": {
          "type": "integer",
          "description": "Instance number extracted from deviceId"
        },
        "creationTime": {
          "type": "string",
          "format": "date-time",
          "description": "ISO 8601 timestamp when the alarm was created"
        },
        "expireTime": {
          "type": "string",
          "format": "date-time",
          "description": "ISO 8601 timestamp when the alarm will expire"
        },
        "muted": {
          "type": "boolean",
          "description": "Whether this alarm is muted by a filter"
        },
        "filterBy": {
          "type": "object",
          "description": "Present only when alarm is muted - describes the matching filter",
          "properties": {
            "uuid": {
              "type": "string",
              "description": "Unique identifier of the filter"
            },
            "functionCode": {
              "type": "integer",
              "description": "Function code the filter matches (optional)"
            },
            "deviceId": {
              "type": "integer",
              "description": "Device ID the filter matches (optional)"
            },
            "code": {
              "type": "integer",
              "description": "Alarm code the filter matches (optional)"
            },
            "duration": {
              "type": "integer",
              "description": "Duration of the filter in seconds"
            },
            "creationTime": {
              "type": "string",
              "format": "date-time",
              "description": "ISO 8601 timestamp when the filter was created"
            },
            "expireTime": {
              "type": "string",
              "format": "date-time",
              "description": "ISO 8601 timestamp when the filter will expire"
            }
          },
          "required": ["uuid", "duration", "creationTime", "expireTime"]
        }
      },
      "patternProperties": {
        "^functionName\\.[A-Z]{2}$": {
          "type": "string",
          "description": "Since 10.3.0: functionName in another language, keyed by the last two letters of the locale (FR, DE, ES, GR, IT, PT, TR today; the set is open). From functions.json; absent when the function code has no entry there or the file did not load. Fall back to functionName"
        }
      },
      "required": [
        "alarmCode",
        "deviceId",
        "functionCode",
        "functionName",
        "instance",
        "creationTime",
        "expireTime",
        "muted"
      ]
    }
  }
}
