{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://heartcortex.ai/schemas/1.0/custom.schema.json",
  "title": "custom",
  "type": "object",
  "required": [
    "name",
    "kind"
  ],
  "properties": {
    "name": {
      "$ref": "common.schema.json#/$defs/capabilityName",
      "x-heart-privacy": "public"
    },
    "kind": {
      "enum": [
        "command",
        "property",
        "event"
      ],
      "x-heart-privacy": "public"
    },
    "title": {
      "type": "string",
      "x-heart-privacy": "public"
    },
    "description": {
      "type": "string",
      "x-heart-privacy": "public"
    },
    "version": {
      "type": "string",
      "x-heart-privacy": "public"
    },
    "deprecated": {
      "type": "boolean",
      "x-heart-privacy": "public"
    },
    "inputSchema": {
      "type": "object",
      "x-heart-privacy": "public"
    },
    "outputSchema": {
      "type": "object",
      "x-heart-privacy": "public"
    },
    "valueSchema": {
      "type": "object",
      "x-heart-privacy": "public"
    },
    "unit": {
      "type": "string",
      "x-heart-privacy": "public"
    },
    "writable": {
      "type": "boolean",
      "x-heart-privacy": "public"
    },
    "risk": {
      "$ref": "common.schema.json#/$defs/risk",
      "x-heart-privacy": "public"
    },
    "privacy": {
      "$ref": "common.schema.json#/$defs/messageLevel",
      "x-heart-privacy": "public"
    },
    "physical": {
      "type": "boolean",
      "x-heart-privacy": "public"
    },
    "idempotent": {
      "type": "boolean",
      "x-heart-privacy": "public"
    },
    "reversible": {
      "type": "boolean",
      "x-heart-privacy": "public"
    },
    "callers": {
      "type": "array",
      "uniqueItems": true,
      "items": {
        "enum": [
          "human",
          "peer",
          "ai",
          "rule"
        ]
      },
      "x-heart-privacy": "public"
    },
    "rhythmName": {
      "type": "string",
      "x-heart-privacy": "public"
    },
    "severity": {
      "$ref": "common.schema.json#/$defs/severity",
      "x-heart-privacy": "public"
    },
    "raises": {
      "description": "Fault code of the Arrhythmia this event raises, if any (Part 3, Section 5). Not an old-style kind.",
      "type": "string",
      "pattern": "^[a-z0-9]+(\\.[a-z0-9-]+)+$",
      "x-heart-privacy": "public"
    },
    "guards": {
      "type": "object",
      "properties": {
        "whenStates": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "whenStatus": {
          "type": "array",
          "items": {
            "$ref": "common.schema.json#/$defs/status"
          }
        },
        "requiresMaintenance": {
          "type": "boolean"
        },
        "minIntervalSec": {
          "type": "integer",
          "minimum": 0
        },
        "maxPerHour": {
          "type": "integer",
          "minimum": 0
        },
        "interlocks": {
          "description": "Conditions that must hold immediately before sending, each a check (common check shape) read from the device at that moment. signal names a Signal Table signal or a property (properties module) of this system; nothing else may be named. A boolean reads as 1 (true) or 0 (false); an enum compares by its index in values. feature defaults to value; withinSec is not used here. An interlock that cannot be read or evaluated counts as failed (409 guard-failed).",
          "type": "array",
          "items": {
            "$ref": "common.schema.json#/$defs/check"
          }
        }
      },
      "x-heart-privacy": "internal"
    },
    "native": {
      "type": "object",
      "required": [
        "protocol",
        "request"
      ],
      "properties": {
        "protocol": {
          "description": "A name from the protocol list, or a reverse-DNS custom adapter.",
          "type": "string",
          "pattern": "^[a-z0-9-]+(\\.[a-z0-9-]+)*$"
        },
        "target": {
          "description": "Adapter-specific address, such as a bus, unit or device.",
          "type": "string"
        },
        "request": {
          "description": "Adapter-specific request. {{arguments.x}} and {{value}} are filled in after validation.",
          "type": [
            "object",
            "string",
            "array"
          ]
        },
        "response": {
          "type": "object",
          "properties": {
            "extract": {
              "type": "object",
              "additionalProperties": {
                "type": "object",
                "required": [
                  "from"
                ],
                "properties": {
                  "from": {
                    "type": "string"
                  },
                  "scale": {
                    "type": "number"
                  },
                  "offset": {
                    "type": "number"
                  },
                  "unit": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "errors": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "match",
              "code"
            ],
            "properties": {
              "match": {
                "type": "string"
              },
              "code": {
                "enum": [
                  "native-failed",
                  "guard-failed",
                  "invalid-request"
                ]
              },
              "message": {
                "type": "string"
              }
            }
          }
        },
        "timeoutMs": {
          "type": "integer",
          "minimum": 1
        },
        "retries": {
          "type": "integer",
          "minimum": 0
        }
      },
      "x-heart-privacy": "private"
    },
    "ext": {
      "$ref": "common.schema.json#/$defs/ext",
      "x-heart-privacy": "private"
    }
  }
}
