{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/bm-e-industrie-com/json-schema/bm-e-industrie-com-command-dispatch-schema.json",
  "title": "CommandDispatch",
  "description": "One attempt to send one command — an attempt, not a result. Failures are recorded and returned with the same shape as successes, because \"we tried to cut the engine and the backend refused\" is a fact the fleet manager needs. Parameter values are deliberately absent: they are operational data and a history row does not need them.",
  "x-generated": "2026-11-19",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/bm-e-industrie-com-track-openapi.yml#/components/schemas/CommandDispatch",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid"
    },
    "device": {
      "type": [
        "string",
        "null"
      ],
      "format": "uuid"
    },
    "device_name": {
      "type": [
        "string",
        "null"
      ]
    },
    "type": {
      "type": "string",
      "description": "The protocol command type, e.g. `engineStop`."
    },
    "label": {
      "type": "string",
      "description": "Human name for the type, resolved server-side."
    },
    "risk": {
      "type": "string",
      "enum": [
        "safe",
        "caution",
        "dangerous"
      ],
      "description": "Ships with the row so a client need not re-derive the tier from the type string — the catalogue that decides it is server-side and grows with the backend's protocols."
    },
    "text_channel": {
      "type": "boolean",
      "description": "Sent over SMS rather than the data channel."
    },
    "status": {
      "type": "string",
      "enum": [
        "sent",
        "held",
        "queued",
        "failed",
        "cancelled",
        "expired"
      ],
      "description": "Not two answers. `held` (BT-28) means the tracker is not connected: BMI Track holds the command, sends it the moment the tracker connects (it becomes `sent`, with `delivered_at`), and until then whoever sent it or an owner can withdraw it (`cancelled`); after a day it is let go unsent (`expired`). An engine stop held is sent only once the vehicle reads stopped. `queued` is the older path, a command left in the tracking backend's own queue, which nothing can withdraw; new commands are never queued there."
    },
    "delivered": {
      "type": "boolean",
      "description": "True for `sent` alone. The judgement is made once, here, so two clients cannot reach different ones."
    },
    "delivered_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time",
      "description": "When a command that was queued reached the device. Null for one sent at once (`created_at` is that moment) and for one still queued."
    },
    "queued": {
      "type": "boolean"
    },
    "held": {
      "type": "boolean"
    },
    "held_until": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time",
      "description": "When a held command is let go if its tracker has not connected."
    },
    "attempts": {
      "type": "integer"
    },
    "cancellable": {
      "type": "boolean",
      "description": "Held, and the caller may withdraw it: whoever sent it, or an owner."
    },
    "cancelled_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "cancelled_by": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid"
        },
        "name": {
          "type": "string"
        }
      }
    },
    "error": {
      "type": [
        "string",
        "null"
      ],
      "description": "Customer-facing sentence on a failure, already stripped of the backend's name and our API path."
    },
    "sent_by": {
      "type": [
        "string",
        "null"
      ]
    },
    "created_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    }
  },
  "required": [
    "id",
    "type",
    "status",
    "delivered"
  ]
}