{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://heartcortex.ai/schemas/1.0/brain.schema.json",
  "title": "brain",
  "description": "GET /heart/v1/brain (module brain, D36): whether this system may consult a brain now, under which lease, and if not, why.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "state"
  ],
  "properties": {
    "state": {
      "enum": [
        "leased",
        "offline",
        "brainless"
      ],
      "x-heart-privacy": "public",
      "description": "leased: it holds an unexpired lease it has checked. offline: auto mode, the link is lost and an offline lease is in use, narrowing with time. brainless: it consults no brain, and runs only Recall, Playbooks a person adopted, Minimum Tending and Actions a person approved (Core Standard 7.8)."
    },
    "why": {
      "enum": [
        "no-lease",
        "lease-expired",
        "brain-off",
        "revoked",
        "restore-pending",
        "invalid-lease",
        "offline-ended",
        "self-cut"
      ],
      "x-heart-privacy": "public",
      "description": "Why it is brainless. restore-pending: a new lease arrived and waits for the owner (brain.restoreNeedsOwner). offline-ended: auto mode reached its time. self-cut: the Core's own tripwire cut the brain (API Standard 7.4 rule 11)."
    },
    "since": {
      "$ref": "common.schema.json#/$defs/timestamp",
      "x-heart-privacy": "internal"
    },
    "lease": {
      "type": "object",
      "x-heart-privacy": "internal",
      "additionalProperties": false,
      "required": [
        "id",
        "models",
        "uses",
        "expiresAt"
      ],
      "properties": {
        "id": {
          "$ref": "common.schema.json#/$defs/uuid"
        },
        "models": {
          "type": "array",
          "items": {
            "$ref": "common.schema.json#/$defs/brainModel"
          }
        },
        "uses": {
          "type": "array",
          "items": {
            "$ref": "common.schema.json#/$defs/brainUse"
          }
        },
        "expiresAt": {
          "$ref": "common.schema.json#/$defs/timestamp",
          "description": "By the device's clock: the received length counted from when it arrived."
        }
      }
    },
    "commandCenter": {
      "type": "object",
      "x-heart-privacy": "internal",
      "additionalProperties": false,
      "required": [
        "url",
        "key"
      ],
      "properties": {
        "url": {
          "type": "string",
          "format": "uri",
          "pattern": "^(https://|http://127\\.0\\.0\\.1(:[0-9]+)?(/|$))",
          "description": "https only; plain http only to 127.0.0.1, for local tests."
        },
        "key": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{43}$",
          "description": "The pinned Ed25519 public key, base64url."
        }
      }
    },
    "restoreNeedsOwner": {
      "type": "boolean",
      "x-heart-privacy": "internal"
    },
    "rejectedAnswers": {
      "type": "integer",
      "minimum": 0,
      "x-heart-privacy": "internal",
      "description": "Brain answers refused since start: unsigned, wrongly signed, for another request, outside the lease, or from a model or use the lease does not name."
    },
    "offline": {
      "type": "object",
      "x-heart-privacy": "internal",
      "additionalProperties": false,
      "required": [
        "enabled"
      ],
      "properties": {
        "enabled": {
          "type": "boolean",
          "description": "Auto mode is on: the owner allowed it with proof of presence."
        },
        "maxSec": {
          "type": "integer",
          "minimum": 0
        },
        "since": {
          "$ref": "common.schema.json#/$defs/timestamp",
          "description": "When the link was lost, while state is offline."
        },
        "uses": {
          "type": "array",
          "items": {
            "$ref": "common.schema.json#/$defs/brainUse"
          },
          "description": "The uses allowed now, after step-down."
        },
        "endsAt": {
          "$ref": "common.schema.json#/$defs/timestamp"
        }
      }
    },
    "ext": {
      "$ref": "common.schema.json#/$defs/ext",
      "x-heart-privacy": "private"
    }
  }
}
