{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/groundmail-dev/json-schema/groundmail-dev-list-automation-runs-response-schema.json",
  "title": "ListAutomationRunsResponse",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/groundmail-dev-automations-api-openapi.yml#/components/schemas/ListAutomationRunsResponse",
  "type": "object",
  "required": [
    "runs"
  ],
  "properties": {
    "runs": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/AutomationRun"
      }
    }
  },
  "$defs": {
    "Automation": {
      "type": "object",
      "required": [
        "id",
        "name",
        "status",
        "trigger",
        "steps",
        "folder",
        "created_at",
        "updated_at"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "status": {
          "type": "string",
          "enum": [
            "draft",
            "active",
            "paused"
          ]
        },
        "trigger": {
          "$ref": "#/$defs/AutomationTrigger"
        },
        "steps": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/AutomationStep"
          },
          "minItems": 1,
          "maxItems": 20
        },
        "folder": {
          "type": [
            "string",
            "null"
          ],
          "description": "Name of the dashboard folder it is filed in, or null."
        },
        "created_at": {
          "type": "string",
          "format": "date-time"
        },
        "updated_at": {
          "type": "string",
          "format": "date-time"
        }
      }
    },
    "AutomationRun": {
      "type": "object",
      "required": [
        "id",
        "automation_id",
        "trigger_event_id",
        "status",
        "current_step",
        "waiting_for_event",
        "wait_timeout_at",
        "context",
        "last_error",
        "cancel_requested_at",
        "started_at",
        "completed_at",
        "created_at",
        "updated_at"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "automation_id": {
          "type": "string"
        },
        "trigger_event_id": {
          "type": [
            "string",
            "null"
          ]
        },
        "status": {
          "type": "string",
          "enum": [
            "queued",
            "running",
            "waiting",
            "completed",
            "failed",
            "cancelled"
          ]
        },
        "current_step": {
          "type": "integer"
        },
        "waiting_for_event": {
          "type": [
            "string",
            "null"
          ]
        },
        "wait_timeout_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "context": {
          "type": "object",
          "additionalProperties": true
        },
        "last_error": {
          "type": [
            "string",
            "null"
          ]
        },
        "cancel_requested_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "started_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "completed_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "created_at": {
          "type": "string",
          "format": "date-time"
        },
        "updated_at": {
          "type": "string",
          "format": "date-time"
        },
        "automation": {
          "$ref": "#/$defs/Automation"
        },
        "trigger_event": {
          "$ref": "#/$defs/EventRecord"
        },
        "steps": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/AutomationRunStep"
          },
          "description": "Present on run detail responses"
        }
      }
    },
    "AutomationRunStep": {
      "type": "object",
      "required": [
        "id",
        "step_index",
        "step_type",
        "status",
        "output",
        "error",
        "started_at",
        "completed_at",
        "created_at",
        "updated_at"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "step_index": {
          "type": "integer"
        },
        "step_type": {
          "type": "string",
          "enum": [
            "delay",
            "send_email",
            "condition",
            "wait_for_event"
          ]
        },
        "status": {
          "type": "string",
          "enum": [
            "started",
            "waiting",
            "completed",
            "failed"
          ]
        },
        "output": {
          "nullable": true
        },
        "error": {
          "type": [
            "string",
            "null"
          ]
        },
        "started_at": {
          "type": "string",
          "format": "date-time"
        },
        "completed_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "created_at": {
          "type": "string",
          "format": "date-time"
        },
        "updated_at": {
          "type": "string",
          "format": "date-time"
        }
      }
    },
    "AutomationStep": {
      "type": "object",
      "required": [
        "type"
      ],
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "delay",
            "send_email",
            "send_sms",
            "condition",
            "wait_for_event"
          ]
        }
      },
      "additionalProperties": true,
      "description": "Step object. Shape depends on `type`:\n- `delay`: `{ type, seconds }`\n- `send_email`: `{ type, email: { from, to, subject?, html?, text?, template?, category? } }`. `category` is `transactional` or `product` (`newsletter` is rejected); when omitted the step sends as its template's category, else `transactional`. Merge fields accept a default: `{{event.data.name | default:\"there\"}}`. Values merged into `html` are HTML-escaped, and `{{unsubscribe_url}}` is filled in with the managed unsubscribe link.\n- `send_sms`: `{ type, sms: { to, body, from?, messaging_service_sid? } }` (requires Twilio integration)\n- `condition`: `{ type, path, operator, value? }` (false stops the run)\n- `wait_for_event`: `{ type, event, timeout_seconds?, on_timeout? }` (`on_timeout` is `continue` or `fail`, default `fail`)\n"
    },
    "AutomationTrigger": {
      "type": "object",
      "required": [
        "type",
        "event"
      ],
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "event"
          ]
        },
        "event": {
          "type": "string"
        },
        "cancel_on_events": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "maxItems": 20,
          "description": "When any listed event fires for the same recipient, cancel queued/running/waiting runs for this automation."
        },
        "once_per_contact": {
          "type": "boolean",
          "description": "Enrol each recipient at most once, ever. Matched on the trigger event's `email` or `user_id`. A later matching event is reported in `enrollment_skips` instead of starting a run."
        },
        "cooldown_days": {
          "type": "integer",
          "minimum": 1,
          "maximum": 3650,
          "description": "Do not enrol the same recipient again within this many days of their last run on this automation. Ignored when `once_per_contact` is true."
        }
      }
    },
    "EventRecord": {
      "type": "object",
      "required": [
        "id",
        "name",
        "user_id",
        "email",
        "data",
        "source",
        "created_at"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "user_id": {
          "type": [
            "string",
            "null"
          ]
        },
        "email": {
          "type": [
            "string",
            "null"
          ],
          "format": "email"
        },
        "data": {
          "type": "object",
          "additionalProperties": true
        },
        "source": {
          "type": "string",
          "enum": [
            "api",
            "dashboard"
          ]
        },
        "created_at": {
          "type": "string",
          "format": "date-time"
        }
      }
    }
  }
}