{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/run402-com/json-schema/run402-com-notification-routing-rule-schema.json",
  "title": "NotificationRoutingRule",
  "description": "One rule = one match -> one destination (notification-channel-routing-telegram, v1.126). Every match dimension is optional; absent = wildcard, ANDed when present. No rules = no Telegram traffic; email/webhook are governed by preferences, untouched by this capability.",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/run402-com-agent-api-openapi.yml#/components/schemas/NotificationRoutingRule",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid"
    },
    "recipient_email": {
      "type": "string"
    },
    "project_id": {
      "type": [
        "string",
        "null"
      ],
      "description": "Wildcard when null."
    },
    "source": {
      "type": [
        "string",
        "null"
      ],
      "enum": [
        "app",
        "platform",
        null
      ],
      "description": "Wildcard when null."
    },
    "event_types": {
      "type": [
        "array",
        "null"
      ],
      "items": {
        "type": "string"
      },
      "description": "Wildcard when null. An explicit [] matches NO event_type — a real, if unsatisfiable, filter — distinct from omitting the field."
    },
    "classes": {
      "type": [
        "array",
        "null"
      ],
      "items": {
        "type": "string"
      },
      "description": "Wildcard when null; same [] semantics as event_types."
    },
    "min_severity": {
      "type": "string",
      "enum": [
        "info",
        "notice",
        "warn",
        "critical"
      ],
      "description": "event-attention-rules: only events at or above this severity match. Never null: a rule created without one stores `notice` when it names no event_types (routine traffic stays in the feed) and `info` when it names some (naming a type opts in to it). Rules that existed before severity shipped read `info` and deliver exactly what they did."
    },
    "group_by": {
      "type": [
        "array",
        "null"
      ],
      "items": {
        "type": "string"
      },
      "description": "event-attention-rules: 1 to 3 top-level payload keys (^[A-Za-z_][A-Za-z0-9_]{0,63}$) whose values group a window's events; needs window_seconds. A rule holds at most 200 distinct keys per window; further keys are counted under (other), so varying a payload value multiplies neither messages nor stored state."
    },
    "window_seconds": {
      "type": [
        "integer",
        "null"
      ],
      "minimum": 60,
      "maximum": 86400,
      "description": "event-attention-rules: reduce a run of events to ONE message per closed wall-clock window (aligned to multiples of window_seconds), with one line per group key ordered by count, ten lines then a summary, plus the total and up to three bounded samples. 60 to 86400. Null delivers per event."
    },
    "next_window_closes_at": {
      "type": "string",
      "format": "date-time",
      "description": "Windowed rules only: when the current window closes — the earliest a message can arrive. Computed at read."
    },
    "escalation_level": {
      "type": [
        "integer",
        "null"
      ],
      "minimum": 1,
      "maximum": 10,
      "description": "event-attention-rules: set exactly for channel escalation — the ladder level a match raises at (the lowest staffed level at or above it)."
    },
    "escalation_refused_count": {
      "type": "integer",
      "description": "Escalation rules: raises the bounds refused (20 per rule per UTC day; 20 open per organization). 0 otherwise."
    },
    "last_escalation_refused_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "channel": {
      "type": "string",
      "enum": [
        "telegram",
        "escalation"
      ],
      "description": "event-attention-rules: `telegram` sends to telegram_binding_id; `escalation` raises on the organization's escalation ladder at escalation_level (mandatory delivery to the contacts there, one-tap ack, deadman climb), and one open escalation per rule: a repeat attaches. Was generic on purpose (widening to email/webhook rules later is a CHECK-constraint migration, not a reshape); v1 only ever writes 'telegram'."
    },
    "telegram_binding_id": {
      "type": "string",
      "format": "uuid"
    },
    "enabled": {
      "type": "boolean"
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    },
    "updated_at": {
      "type": "string",
      "format": "date-time"
    }
  }
}