{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://tylereno.me/cel/schemas/response_machine.json",
  "title": "CelResponseMachine",
  "description": "Emergency response finite state machine in speakable CEL words. Names allowed postures and transitions. Does not encode commissioning evidence, SAT gates, CAP fields, or actuation.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "id",
    "version",
    "cel_spec",
    "title",
    "incident_types",
    "subject_kind",
    "initial_state",
    "states",
    "transitions"
  ],
  "properties": {
    "id": {
      "type": "string",
      "pattern": "^cel\\.response\\.[a-z][a-z0-9_]*$"
    },
    "version": { "type": "string", "minLength": 1 },
    "cel_spec": { "type": "string", "const": "0.1.0" },
    "title": { "type": "string", "minLength": 1 },
    "description": { "type": "string" },
    "incident_types": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {
        "type": "string",
        "pattern": "^disaster(\\.[a-z][a-z0-9_]*)+$",
        "description": "CEL incident words this machine may apply to."
      }
    },
    "subject_kind": {
      "type": "string",
      "const": "site",
      "description": "v0 machines apply to a site. Not an OIDF Deployment or Asset subject."
    },
    "initial_state": {
      "type": "string",
      "pattern": "^response\\.[a-z][a-z0-9_]*$"
    },
    "states": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "https://tylereno.me/cel/schemas/response_state.json" }
    },
    "transitions": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/$defs/responseTransition" }
    }
  },
  "$defs": {
    "responseTransition": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "event", "from", "to"],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]*$"
        },
        "event": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]*(\\.[a-z][a-z0-9_]*)+$",
          "description": "Named transition vocabulary. Consumers fire this event; CEL does not."
        },
        "from": {
          "type": "string",
          "pattern": "^response\\.[a-z][a-z0-9_]*$"
        },
        "to": {
          "type": "string",
          "pattern": "^response\\.[a-z][a-z0-9_]*$"
        },
        "description": { "type": "string" }
      }
    }
  }
}
