{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://interchange.stellarview.net/schemas/path.schema.json",
  "title": "A rule path: which events it takes (by name and metadata), the policy that requires it, the action, who is told, the systems it uses and how fast",
  "type": "object",
  "required": ["id", "mode", "priority", "match", "policy", "action", "systems", "timing"],
  "additionalProperties": false,
  "properties": {
    "id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9_.-]*$" },
    "about": { "type": "string" },
    "mode": {
      "enum": ["exclusive", "additive"],
      "description": "exclusive: of every exclusive path that matches, one is chosen by precedence. additive: runs whenever it matches, beside the chosen one."
    },
    "priority": { "type": "integer", "description": "Breaks a tie in specificity between exclusive paths: higher wins." },
    "match": {
      "type": "object",
      "minProperties": 1,
      "additionalProperties": false,
      "description": "Every criterion given must hold.",
      "properties": {
        "event_types": {
          "type": "array",
          "minItems": 1,
          "items": { "type": "string", "pattern": "^([a-z][a-z0-9_]*\\.[a-z][a-z0-9_]*\\.[a-z][a-z0-9_]*|[a-z][a-z0-9_]*\\.\\*)$" },
          "description": "Catalogue ids, or <system>.* for a whole system."
        },
        "asset_classes": { "type": "array", "minItems": 1, "items": { "$ref": "common.schema.json#/$defs/asset_class_id" } },
        "criticality": { "type": "array", "minItems": 1, "items": { "enum": ["low", "medium", "high", "critical", "not known"] } },
        "areas": { "type": "array", "minItems": 1, "items": { "type": "string" }, "description": "Building, level, section or room names from the target's snapshot." },
        "hours": {
          "type": "object",
          "required": ["from", "to", "tz"],
          "additionalProperties": false,
          "description": "The local time the event occurred. from after to spans midnight.",
          "properties": { "from": { "type": "string", "pattern": "^\\d{2}:\\d{2}$" }, "to": { "type": "string", "pattern": "^\\d{2}:\\d{2}$" }, "tz": { "type": "string" } }
        },
        "min_severity": { "$ref": "common.schema.json#/$defs/severity" }
      }
    },
    "policy": {
      "description": "The policy, process or routine document that requires this path.",
      "oneOf": [
        {
          "type": "object",
          "required": ["state", "document", "clause"],
          "additionalProperties": false,
          "properties": { "state": { "const": "linked" }, "document": { "type": "string" }, "sha256": { "type": "string" }, "clause": { "type": "string" } }
        },
        {
          "type": "object",
          "required": ["state", "needs"],
          "additionalProperties": false,
          "properties": { "state": { "const": "to_link" }, "needs": { "type": "string", "description": "The document still to ingest and link." } }
        }
      ]
    },
    "action": {
      "type": "object",
      "required": ["kind"],
      "additionalProperties": false,
      "properties": {
        "kind": { "enum": ["notify", "ticket", "work_order", "checklist"] },
        "task": { "type": "string" },
        "checklist": { "type": "string", "description": "The checklist to run (a Mission Studio checklist id)." },
        "priority": { "enum": ["low", "medium", "high", "highest"] }
      }
    },
    "tell": { "type": ["string", "null"], "description": "An alert rule id (data/alerts/rules.json): the roles, the route and the escalation." },
    "systems": {
      "type": "array",
      "items": { "enum": ["alert", "jira", "i3", "checklist"] },
      "description": "alert: the alert rule named by tell. jira: a help desk ticket. i3: a work order to the CMMS. checklist: a checklist assignment."
    },
    "timing": {
      "type": "object",
      "required": ["respond_within_s"],
      "additionalProperties": false,
      "properties": { "respond_within_s": { "type": "integer", "minimum": 1 }, "basis": { "type": "string" } }
    }
  }
}
