{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://heartcortex.ai/schemas/1.0/brain-signal.schema.json",
  "title": "brain signal",
  "description": "Body of POST /heart/v1/brain/signal, also carried in a lease renewal reply (API Standard 7.4 rule 8, D36). The one kind of message a Command Center may send a device, and it only lowers risk: no signal can restore a brain, add a model or use, raise autonomy, approve an Action or change a setting. Refused if its signature does not check, it is for another system, it is older than 300 seconds, or its id was seen before.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "signal",
    "signature"
  ],
  "properties": {
    "signal": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "system",
        "id",
        "kind",
        "at"
      ],
      "properties": {
        "system": {
          "$ref": "common.schema.json#/$defs/systemId"
        },
        "id": {
          "$ref": "common.schema.json#/$defs/uuid",
          "description": "Used once: a repeat is ignored."
        },
        "kind": {
          "enum": [
            "brain-off",
            "revoke-model",
            "revoke-use",
            "autonomy-stop"
          ],
          "description": "brain-off: drop the lease now. revoke-model: remove one model from the lease. revoke-use: remove one use. autonomy-stop: the same as POST /heart/v1/tending/stop."
        },
        "model": {
          "$ref": "common.schema.json#/$defs/brainModel",
          "description": "For revoke-model."
        },
        "use": {
          "$ref": "common.schema.json#/$defs/brainUse",
          "description": "For revoke-use."
        },
        "scope": {
          "type": "string",
          "maxLength": 200,
          "description": "Informative: the switch this signal is part of, such as device, fleet:<label>, model:<id>, use:propose, profile:heavy-machine or all."
        },
        "reason": {
          "type": "string",
          "maxLength": 500
        },
        "at": {
          "$ref": "common.schema.json#/$defs/timestamp"
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "kind": {
                "const": "revoke-model"
              }
            }
          },
          "then": {
            "required": [
              "model"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "const": "revoke-use"
              }
            }
          },
          "then": {
            "required": [
              "use"
            ]
          }
        }
      ]
    },
    "signature": {
      "type": "string",
      "pattern": "^[A-Za-z0-9_-]{86}$",
      "description": "base64url Ed25519 signature over the RFC 8785 JSON of signal, with the pinned Command Center key."
    }
  }
}
