{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://interchange.stellarview.net/schemas/alert.schema.json",
  "title": "An alert record: one event told to people, with every send, escalation and the acknowledgement",
  "type": "object",
  "required": [
    "kind",
    "alert_id",
    "event_id",
    "event_type",
    "severity",
    "rule",
    "roles",
    "role_basis",
    "state",
    "raised_at",
    "sends",
    "escalations",
    "asset"
  ],
  "additionalProperties": false,
  "properties": {
    "kind": {
      "const": "alert"
    },
    "alert_id": {
      "$ref": "common.schema.json#/$defs/uuid"
    },
    "event_id": {
      "$ref": "common.schema.json#/$defs/uuid"
    },
    "event_type": {
      "$ref": "common.schema.json#/$defs/event_type_id"
    },
    "severity": {
      "$ref": "common.schema.json#/$defs/severity"
    },
    "rule": {
      "type": "string"
    },
    "asset": {
      "$ref": "common.schema.json#/$defs/asset_ref"
    },
    "roles": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "role_basis": {
      "type": "string",
      "description": "How the roles were chosen: the asset's role links, the rule's list, or the rule's stated roles for an asset with none."
    },
    "state": {
      "enum": [
        "open",
        "acknowledged"
      ]
    },
    "raised_at": {
      "$ref": "common.schema.json#/$defs/time"
    },
    "escalation": {
      "type": [
        "string",
        "null"
      ]
    },
    "sends": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "role",
          "channel",
          "address",
          "state",
          "at"
        ],
        "additionalProperties": false,
        "properties": {
          "role": {
            "type": "string"
          },
          "channel": {
            "type": "string"
          },
          "address": {
            "type": "string"
          },
          "state": {
            "enum": [
              "sent_to_stub",
              "sent",
              "waiting"
            ]
          },
          "message_id": {
            "type": "string"
          },
          "error": {
            "type": "string"
          },
          "at": {
            "$ref": "common.schema.json#/$defs/time"
          },
          "step": {
            "type": "integer",
            "minimum": 0,
            "description": "0 for the first send; the escalation step number after."
          }
        }
      }
    },
    "escalations": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "step",
          "to_role",
          "at"
        ],
        "additionalProperties": false,
        "properties": {
          "step": {
            "type": "integer",
            "minimum": 1
          },
          "to_role": {
            "type": "string"
          },
          "at": {
            "$ref": "common.schema.json#/$defs/time"
          }
        }
      }
    },
    "ack": {
      "$ref": "alert_ack.schema.json"
    },
    "path": {
      "type": "string",
      "description": "The rule path that named this alert rule."
    }
  }
}