{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://heartcortex.ai/schemas/1.0/lifecycle-request.schema.json",
  "title": "lifecycle request",
  "description": "Body of POST /heart/v1/lifecycle/{operation} (API Standard 13.2 rule 3, decision D29). The operation in the path is the one carried out; operation in the body is optional and, if given, MUST equal it. Unknown fields are refused with 400 invalid-request. actionId and presence carry a person's proof of presence in the same request (API Standard 6.3); they are not part of the Action's arguments.",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "operation": {
      "description": "One of the standard operations, or a vendor operation starting with x-.",
      "anyOf": [
        {
          "enum": [
            "restart",
            "shutdown",
            "sleep",
            "wake",
            "drain",
            "reload",
            "power-cycle",
            "safe-mode",
            "maintenance-on",
            "maintenance-off",
            "reset-config",
            "reset-network",
            "clear-data",
            "factory-reset",
            "decommission"
          ]
        },
        {
          "type": "string",
          "pattern": "^x-[a-z0-9][a-z0-9-]*$"
        }
      ]
    },
    "mode": {
      "enum": [
        "graceful",
        "force"
      ],
      "default": "graceful",
      "description": "restart and shutdown only. force skips saving state and draining, so it is destructive."
    },
    "target": {
      "type": "string",
      "pattern": "^(system|heart|component:[A-Za-z0-9._:-]+)$",
      "default": "system",
      "description": "What restarts: the whole system, the HEART alone, or one component. restart only."
    },
    "timeoutSec": {
      "type": "integer",
      "minimum": 1,
      "maximum": 86400,
      "description": "Longest a graceful operation may take. A graceful restart that passes it fails; it never becomes a force restart by itself."
    },
    "drainSec": {
      "type": "integer",
      "minimum": 0,
      "maximum": 86400,
      "description": "Time to finish running work before a restart or shutdown, or the length of a drain."
    },
    "delaySec": {
      "type": "integer",
      "minimum": 0,
      "maximum": 2592000,
      "description": "Wait before starting. Above 0, the operation is carried out as a schedule (module schedules), where it can be seen and removed."
    },
    "depth": {
      "enum": [
        "light",
        "deep",
        "hibernate"
      ],
      "description": "sleep only. A system in deep sleep or hibernation cannot answer HTTP; see card.lifecycle.wakeSources."
    },
    "wakeAt": {
      "$ref": "common.schema.json#/$defs/timestamp",
      "description": "sleep only: when to wake. At most one of wakeAt and durationSec."
    },
    "durationSec": {
      "type": "integer",
      "minimum": 1,
      "maximum": 2592000,
      "description": "sleep: how long to sleep. maintenance-on: required; how long maintenance lasts, at most card.limits.maxMaintenanceSec."
    },
    "reason": {
      "type": "string",
      "maxLength": 500,
      "x-heart-privacy": "internal",
      "description": "Plain words for the audit record."
    },
    "actionId": {
      "$ref": "common.schema.json#/$defs/actionId"
    },
    "presence": {
      "description": "Proof of presence for the digest of the Action named by actionId (API Standard 6.3, rule 3). Needs actionId.",
      "$ref": "common.schema.json#/$defs/presence"
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "operation": {
            "const": "maintenance-on"
          }
        },
        "required": [
          "operation"
        ]
      },
      "then": {
        "required": [
          "durationSec"
        ]
      }
    },
    {
      "not": {
        "required": [
          "wakeAt",
          "durationSec"
        ]
      }
    }
  ],
  "dependentRequired": {
    "presence": [
      "actionId"
    ]
  }
}
