{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/scrip-dev/json-schema/scrip-dev-automation-response-schema.json",
  "title": "AutomationResponse",
  "description": "An automation: an event that Scrip sends on a schedule, with its trigger, status and run history.",
  "x-generated": "2026-11-24",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/scrip-dev-openapi.json#/components/schemas/AutomationResponse",
  "properties": {
    "created_at": {
      "description": "When this automation was created",
      "format": "date-time",
      "type": "string"
    },
    "description": {
      "description": "Optional human-readable description of what this automation does",
      "type": "string"
    },
    "error_message": {
      "description": "Error message if the one-time automation failed",
      "type": "string"
    },
    "event_data": {
      "description": "Event data submitted when this automation fires",
      "type": "object"
    },
    "event_type": {
      "description": "The name of the events this automation sends, such as `weekly_reminder`. Rules read it as `event.type`.",
      "type": "string"
    },
    "execution_completed_at": {
      "description": "When the current fan-out execution completed",
      "format": "date-time",
      "type": "string"
    },
    "execution_error": {
      "description": "Error message if the fan-out execution failed, or JSON-encoded diagnostics for completed runs with CEL eval skips",
      "type": "string"
    },
    "execution_started_at": {
      "description": "When the current fan-out execution started",
      "format": "date-time",
      "type": "string"
    },
    "execution_status": {
      "description": "Progress of the current fan-out run, separate from `status`.\n- IDLE: no run is in progress.\n- EXECUTING: sending events to matching participants.\n- COMPLETED: latest run finished.\n- FAILED: latest run stopped with an error.",
      "enum": [
        "IDLE",
        "EXECUTING",
        "COMPLETED",
        "FAILED"
      ],
      "type": "string"
    },
    "filter_hints": {
      "description": "Checks derived from `participant_filter` that narrow the participants to consider. Scrip still evaluates the full CEL filter for each candidate.",
      "items": {
        "$ref": "#/$defs/AutomationFilterHint"
      },
      "type": "array"
    },
    "guard_condition": {
      "description": "CEL expression evaluated at trigger time; skips the participant if false",
      "type": "string"
    },
    "id": {
      "description": "Unique identifier for this automation",
      "format": "uuid",
      "type": "string"
    },
    "last_error": {
      "description": "Error message from the most recent cron execution, if any (cron trigger only)",
      "type": "string"
    },
    "last_evaluated_at": {
      "description": "When participant filters were last evaluated (PARTICIPANT_STATE trigger only)",
      "format": "date-time",
      "type": "string"
    },
    "last_run_at": {
      "description": "When this automation last fired (cron trigger only)",
      "format": "date-time",
      "type": "string"
    },
    "name": {
      "description": "Human-readable label for this automation",
      "type": "string"
    },
    "next_run_at": {
      "description": "When this automation will next fire (cron trigger only)",
      "format": "date-time",
      "type": "string"
    },
    "participant_filter": {
      "description": "CEL expression that determines which participants are enrolled",
      "type": "string"
    },
    "participant_id": {
      "description": "Target participant for program-scoped one-time automations",
      "format": "uuid",
      "type": "string"
    },
    "participants_processed": {
      "description": "Participants Scrip has sent the event to in the current run so far.",
      "type": "integer"
    },
    "participants_skipped_error": {
      "description": "Participants skipped because participant_filter or guard_condition CEL evaluation errored",
      "type": "integer"
    },
    "participants_total": {
      "description": "Total candidate participants in the current fan-out run.",
      "type": "integer"
    },
    "processed_at": {
      "description": "When this one-time automation was processed",
      "format": "date-time",
      "type": "string"
    },
    "program_id": {
      "description": "The program this automation belongs to",
      "format": "uuid",
      "type": "string"
    },
    "scope": {
      "description": "Whether the automation sends one event to the program (PROGRAM) or one event to each matching participant (PARTICIPANTS).",
      "enum": [
        "PROGRAM",
        "PARTICIPANTS"
      ],
      "type": "string"
    },
    "source": {
      "description": "How the automation was created.\n- API: created through the automations API.\n- RULE_ACTION: created by a SCHEDULE_EVENT or BROADCAST rule action.\n- SYSTEM: created by Scrip for scheduled work such as tier expiration.",
      "enum": [
        "API",
        "RULE_ACTION",
        "SYSTEM"
      ],
      "type": "string"
    },
    "source_event_id": {
      "description": "The event whose processing created this automation. Omitted when no source event is recorded, for example on automations created through the API.",
      "format": "uuid",
      "type": "string"
    },
    "source_rule_id": {
      "description": "The rule whose action created this automation. Omitted when no rule action created it, including automations created through the API.",
      "format": "uuid",
      "type": "string"
    },
    "status": {
      "description": "Whether the automation can fire.\n- ACTIVE: fires when its trigger is due.\n- PAUSED: does not fire until you set it back to ACTIVE.\n- COMPLETED: a one-time automation that has fired; it cannot fire again.\n- FAILED: stopped after a failure; set it to ACTIVE to try again.\n- ARCHIVED: removed from use; it never fires again.",
      "enum": [
        "ACTIVE",
        "PAUSED",
        "COMPLETED",
        "FAILED",
        "ARCHIVED"
      ],
      "type": "string"
    },
    "trigger": {
      "$ref": "#/$defs/AutomationTrigger",
      "description": "Trigger configuration (type, schedule, and timing)"
    },
    "updated_at": {
      "description": "When this automation was last updated",
      "format": "date-time",
      "type": "string"
    },
    "warnings": {
      "description": "Advisories about `participant_filter` and `guard_condition`, such as a counter, tag or attribute key that no rule in the program writes. They appear on create and update only, and they never block the save.",
      "items": {
        "$ref": "#/$defs/RuleWarning"
      },
      "type": "array"
    }
  },
  "type": "object",
  "$defs": {
    "AutomationAttributeDateScheduleConfig": {
      "description": "Use when schedule_type is ATTRIBUTE_DATE. Reads a date from each participant's attribute.",
      "properties": {
        "attribute_key": {
          "description": "Participant attribute containing the date value.",
          "type": "string"
        },
        "date_format": {
          "description": "Format stored in the participant attribute: MM-DD recurs yearly; YYYY-MM-DD fires for one calendar date.",
          "enum": [
            "MM-DD",
            "YYYY-MM-DD"
          ],
          "type": "string"
        },
        "offset": {
          "description": "Optional signed duration applied to the attribute date. Accepted units are ns, us or µs, ms, s, m, h, d, and w; units may be combined, while months and years are not accepted.",
          "type": "string"
        }
      },
      "required": [
        "attribute_key",
        "date_format"
      ],
      "title": "ATTRIBUTE_DATE schedule configuration",
      "type": "object"
    },
    "AutomationCronScheduleConfig": {
      "description": "Use when schedule_type is CRON. All subscribed participants share the same calendar schedule.",
      "properties": {
        "expression": {
          "description": "Five-field cron expression or descriptor such as @hourly or @daily; inline timezone directives are not accepted.",
          "type": "string"
        }
      },
      "required": [
        "expression"
      ],
      "title": "CRON schedule configuration",
      "type": "object"
    },
    "AutomationFilterHint": {
      "description": "A check derived from `participant_filter` that narrows the participants to consider.",
      "properties": {
        "type": {
          "description": "Check to apply before evaluating `participant_filter`.\n- HAS_TAG: value is a participant tag.\n- HAS_ATTRIBUTE: value is an attribute key.\n- HAS_COUNTER: value is a counter key.",
          "enum": [
            "HAS_TAG",
            "HAS_ATTRIBUTE",
            "HAS_COUNTER"
          ],
          "type": "string"
        },
        "value": {
          "description": "Non-empty tag value, attribute key, or counter key interpreted according to type.",
          "minLength": 1,
          "type": "string"
        }
      },
      "required": [
        "type",
        "value"
      ],
      "title": "Automation filter hint",
      "type": "object"
    },
    "AutomationIntervalScheduleConfig": {
      "description": "Use when schedule_type is INTERVAL. Each participant fires relative to their own subscription time.",
      "properties": {
        "interval": {
          "description": "Positive duration between firings. Accepted units are ns, us or µs, ms, s, m, h, d, and w; units may be combined, while months and years are not accepted.",
          "type": "string"
        }
      },
      "required": [
        "interval"
      ],
      "title": "INTERVAL schedule configuration",
      "type": "object"
    },
    "AutomationThresholdScheduleConfig": {
      "description": "Use when schedule_type is THRESHOLD. Fires after a participant counter satisfies the comparison.",
      "properties": {
        "counter_key": {
          "description": "Participant counter to compare.",
          "type": "string"
        },
        "delay": {
          "description": "Non-negative duration to wait after the comparison matches before firing. Accepted units are ns, us or µs, ms, s, m, h, d, and w; units may be combined, while months and years are not accepted.",
          "type": "string"
        },
        "operator": {
          "description": "Comparison applied between the participant counter and threshold.",
          "enum": [
            ">=",
            ">",
            "==",
            "<=",
            "<"
          ],
          "type": "string"
        },
        "threshold": {
          "description": "Numeric counter value used by operator for the comparison; explicit 0 is valid.",
          "type": "number"
        }
      },
      "required": [
        "counter_key",
        "operator",
        "threshold",
        "delay"
      ],
      "title": "THRESHOLD schedule configuration",
      "type": "object"
    },
    "AutomationTrigger": {
      "description": "What starts an automation: a cron schedule, a single time, or a participant-state schedule.",
      "properties": {
        "cron_expression": {
          "description": "Cron expression for recurring schedules (cron trigger only)",
          "type": "string"
        },
        "schedule_config": {
          "anyOf": [
            {
              "$ref": "#/$defs/AutomationAttributeDateScheduleConfig"
            },
            {
              "$ref": "#/$defs/AutomationIntervalScheduleConfig"
            },
            {
              "$ref": "#/$defs/AutomationCronScheduleConfig"
            },
            {
              "$ref": "#/$defs/AutomationThresholdScheduleConfig"
            }
          ],
          "description": "Configuration selected by schedule_type for a PARTICIPANT_STATE trigger. The matching anyOf branch documents its required fields; unrecognized keys are ignored.",
          "type": "object"
        },
        "schedule_type": {
          "description": "Subscription schedule for a PARTICIPANT_STATE trigger.\n- ATTRIBUTE_DATE: derive each participant's trigger time from a date-valued attribute.\n- INTERVAL: fire at a fixed duration relative to each participant's subscription.\n- CRON: fire all subscribed participants on a shared cron schedule.\n- THRESHOLD: fire after a participant counter satisfies a comparison.",
          "enum": [
            "ATTRIBUTE_DATE",
            "INTERVAL",
            "CRON",
            "THRESHOLD"
          ],
          "type": "string"
        },
        "timezone": {
          "description": "IANA timezone for schedule evaluation (defaults to UTC)",
          "type": "string"
        },
        "trigger_at": {
          "description": "When to fire (ONE_TIME trigger only, RFC 3339, must be in the future; omit to run now)",
          "format": "date-time",
          "type": "string"
        },
        "type": {
          "description": "What starts the automation.\n- CRON: fires repeatedly on `cron_expression` in `timezone`.\n- ONE_TIME: fires once at `trigger_at`, or as soon as possible when `trigger_at` is omitted.\n- PARTICIPANT_STATE: keeps a subscription for each matching participant using `schedule_type` and `schedule_config`.",
          "enum": [
            "CRON",
            "ONE_TIME",
            "PARTICIPANT_STATE"
          ],
          "type": "string"
        }
      },
      "required": [
        "type"
      ],
      "type": "object"
    },
    "RuleWarning": {
      "description": "A warning about a rule's condition or actions. It does not block the change. The usual cases are a reference to a key that no rule writes, and a reference to an event field that no recent event has.",
      "properties": {
        "client_ref": {
          "description": "The `client_ref` of the rule, when the rule is new.",
          "type": "string"
        },
        "code": {
          "description": "Warning code (e.g. `unknown_state_key`, `event_field_not_received`, `default_accessor_has`, `deprecated_alias`, `possible_unmarked_expression`, `missing_participant_context`).",
          "type": "string"
        },
        "event_type": {
          "description": "The event type the warning is about. Present only on an `event_field_not_received` warning for a rule whose condition checks `event.type` against fixed values. Omitted otherwise.",
          "type": "string"
        },
        "key": {
          "description": "The referenced key, as written in the condition. For an `event_field_not_received` warning it is the event field path.",
          "type": "string"
        },
        "kind": {
          "description": "Kind of reference: `counter`, `tag`, `attribute`, `alias`, or `field` for an event field.",
          "type": "string"
        },
        "message": {
          "description": "Human-readable explanation (includes the suggestion when one exists).",
          "type": "string"
        },
        "rule_id": {
          "description": "Rule identity is populated for complete-configuration validation. The\nsingle-rule authoring surfaces omit these fields.",
          "type": "string"
        },
        "rule_set_id": {
          "description": "The id of the rule set that holds the rule.",
          "type": "string"
        },
        "scope": {
          "description": "Where the referenced state belongs: `participant`, `program`, `group`, or `event` for an event field.",
          "type": "string"
        },
        "suggestion": {
          "description": "Closest known key, when a near-match exists. Empty otherwise.",
          "type": "string"
        }
      },
      "type": "object"
    }
  }
}