{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docsiren.app/spec/dasf-v1.0.json",
  "title": "Document Alert Specification Format (DASF) v1.0",
  "description": "Normative JSON Schema for DASF v1.0. Defines the object model for document deadline, expiration, and compliance alerts as specified at https://docsiren.app/spec/.",
  "type": "object",
  "required": ["dasf_version", "alert_event"],
  "additionalProperties": false,
  "properties": {
    "dasf_version": {
      "type": "string",
      "description": "DASF version string in MAJOR.MINOR form. For payloads conforming to this revision, MUST equal '1.0'.",
      "pattern": "^[0-9]+\\.[0-9]+$",
      "examples": ["1.0"]
    },
    "alert_event": { "$ref": "#/$defs/AlertEvent" }
  },
  "$defs": {
    "AlertEvent": {
      "type": "object",
      "description": "Root object representing a single notifiable event about a single document subject.",
      "required": ["id", "severity", "issued_at", "subject", "channels"],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200,
          "description": "Globally unique identifier. Producers SHOULD use ULID, UUIDv7, or a comparable lexicographically-sortable identifier."
        },
        "severity": {
          "type": "string",
          "enum": ["info", "warning", "urgent", "critical"],
          "description": "Urgency level. See DASF spec section 6."
        },
        "issued_at": {
          "type": "string",
          "format": "date-time",
          "description": "Instant the alert was generated. RFC 3339 UTC with 'Z' suffix.",
          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\\.[0-9]+)?Z$"
        },
        "deadline_at": {
          "type": "string",
          "format": "date-time",
          "description": "Instant the underlying obligation must be discharged. RFC 3339 UTC with 'Z' suffix.",
          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\\.[0-9]+)?Z$"
        },
        "last_reminder_at": {
          "type": "string",
          "format": "date-time",
          "description": "Instant of the most recent prior reminder for the same alert.",
          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\\.[0-9]+)?Z$"
        },
        "subject": { "$ref": "#/$defs/DocumentSubject" },
        "channels": {
          "type": "array",
          "minItems": 1,
          "items": { "$ref": "#/$defs/NotificationChannel" }
        },
        "escalation": {
          "type": "array",
          "items": { "$ref": "#/$defs/EscalationRule" }
        },
        "retry_policy": { "$ref": "#/$defs/RetryPolicy" },
        "idempotency_key": {
          "type": "string",
          "minLength": 1,
          "maxLength": 256,
          "description": "Deterministic identifier permitting consumers to deduplicate. SHOULD be deterministic given the same logical alert."
        },
        "locale": {
          "type": "string",
          "description": "BCP 47 locale tag (e.g. 'en-US', 'ru-RU').",
          "pattern": "^[a-zA-Z]{2,3}(-[a-zA-Z0-9]{2,8})*$"
        },
        "tags": {
          "type": "array",
          "items": { "type": "string", "minLength": 1, "maxLength": 64 },
          "uniqueItems": true
        }
      },
      "patternProperties": {
        "^x_": {}
      },
      "additionalProperties": false
    },
    "DocumentSubject": {
      "type": "object",
      "description": "Identifies the document and its attached obligation.",
      "required": ["type"],
      "properties": {
        "type": {
          "type": "string",
          "minLength": 1,
          "maxLength": 64,
          "description": "Document class identifier. Recommended values: InsurancePolicy, DriverLicense, USDOTAuthority, SR22Filing, UCRRegistration, HIPAABreachReport, WorkersCompPolicy, BusinessLicense, Permit, TaxFiling."
        },
        "identifier": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200,
          "description": "Stable identifier for the document instance."
        },
        "jurisdiction": {
          "type": "string",
          "description": "ISO 3166-2 jurisdiction code (e.g. 'US-NY', 'US-CA', 'RU').",
          "pattern": "^[A-Z]{2}(-[A-Z0-9]{1,3})?$"
        },
        "obligation": {
          "type": "string",
          "enum": ["renewal", "filing", "payment", "review", "upload", "signature", "notification", "response"],
          "description": "Action required of the recipient."
        },
        "human_label": {
          "type": "string",
          "maxLength": 280,
          "description": "Human-readable description for display."
        },
        "references": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["uri"],
            "properties": {
              "uri": { "type": "string", "format": "uri" },
              "rel": { "type": "string", "enum": ["source", "regulation", "contract", "schema", "related"] },
              "media_type": { "type": "string", "pattern": "^[a-zA-Z0-9!#$&^_.+-]{1,127}/[a-zA-Z0-9!#$&^_.+-]{1,127}$" }
            },
            "patternProperties": { "^x_": {} },
            "additionalProperties": false
          }
        }
      },
      "patternProperties": { "^x_": {} },
      "additionalProperties": false
    },
    "NotificationChannel": {
      "type": "object",
      "description": "A single delivery target.",
      "required": ["type", "address"],
      "properties": {
        "type": {
          "type": "string",
          "enum": ["email", "sms", "push", "webhook", "voice", "postal"],
          "description": "Channel type."
        },
        "address": {
          "type": "string",
          "minLength": 1,
          "maxLength": 500,
          "description": "Channel-specific delivery address. Format constrained by channel type."
        },
        "locale": {
          "type": "string",
          "pattern": "^[a-zA-Z]{2,3}(-[a-zA-Z0-9]{2,8})*$"
        },
        "quiet_hours": {
          "type": "string",
          "description": "Local quiet window in HH:MM-HH:MM TZ form, e.g. '22:00-07:00 America/New_York'.",
          "pattern": "^[0-9]{2}:[0-9]{2}-[0-9]{2}:[0-9]{2} [A-Za-z_]+/[A-Za-z_]+(/[A-Za-z_]+)?$"
        },
        "signed": {
          "type": "boolean",
          "description": "For webhook channels: requires HMAC signature on delivery."
        },
        "options": {
          "type": "object",
          "description": "Channel-specific delivery options.",
          "additionalProperties": true
        }
      },
      "patternProperties": { "^x_": {} },
      "additionalProperties": false,
      "allOf": [
        {
          "if": { "properties": { "type": { "const": "webhook" } } },
          "then": { "properties": { "address": { "pattern": "^https://" } } }
        }
      ]
    },
    "EscalationRule": {
      "type": "object",
      "description": "Ordered policy for reacting to non-acknowledgement.",
      "required": ["after", "action"],
      "properties": {
        "after": {
          "type": "string",
          "description": "ISO 8601 duration since issued_at after which the rule fires.",
          "pattern": "^P(?!$)((\\d+Y)?(\\d+M)?(\\d+W)?(\\d+D)?)?(T(?=\\d)(\\d+H)?(\\d+M)?(\\d+(\\.\\d+)?S)?)?$"
        },
        "action": {
          "type": "string",
          "enum": ["resend", "escalate", "elevate_severity", "cancel"]
        },
        "severity": {
          "type": "string",
          "enum": ["info", "warning", "urgent", "critical"]
        },
        "to": {
          "type": "string",
          "maxLength": 500,
          "description": "For 'escalate' action: alternate channel address."
        },
        "channel_type": {
          "type": "string",
          "enum": ["email", "sms", "push", "webhook", "voice", "postal"]
        },
        "condition": {
          "type": "string",
          "enum": ["not_acknowledged", "not_delivered", "not_completed"],
          "default": "not_acknowledged"
        }
      },
      "patternProperties": { "^x_": {} },
      "additionalProperties": false
    },
    "RetryPolicy": {
      "type": "object",
      "description": "Channel-level delivery retry behavior.",
      "required": ["max_attempts", "backoff"],
      "properties": {
        "max_attempts": {
          "type": "integer",
          "minimum": 1,
          "maximum": 20,
          "description": "Total delivery attempts including the first."
        },
        "backoff": {
          "type": "string",
          "enum": ["fixed", "linear", "exponential", "exponential_jitter"]
        },
        "initial_delay": {
          "type": "string",
          "description": "ISO 8601 duration before second attempt. Default 'PT30S'.",
          "pattern": "^P(?!$)((\\d+Y)?(\\d+M)?(\\d+W)?(\\d+D)?)?(T(?=\\d)(\\d+H)?(\\d+M)?(\\d+(\\.\\d+)?S)?)?$",
          "default": "PT30S"
        },
        "max_delay": {
          "type": "string",
          "description": "ISO 8601 duration cap on backoff. Default 'PT1H'.",
          "pattern": "^P(?!$)((\\d+Y)?(\\d+M)?(\\d+W)?(\\d+D)?)?(T(?=\\d)(\\d+H)?(\\d+M)?(\\d+(\\.\\d+)?S)?)?$",
          "default": "PT1H"
        }
      },
      "patternProperties": { "^x_": {} },
      "additionalProperties": false
    }
  }
}
