{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/yardstick-team/json-schema/yardstick-team-automation-rule-schema.json",
  "title": "AutomationRule",
  "x-generated": "2026-11-29",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/yardstick-team-openapi.json#/components/schemas/AutomationRule",
  "type": "object",
  "properties": {
    "pipeline_template_id": {
      "type": [
        "string",
        "null"
      ],
      "minLength": 1
    },
    "job_id": {
      "type": [
        "string",
        "null"
      ],
      "minLength": 1
    },
    "needs_step_pick": {
      "type": "boolean"
    },
    "name": {
      "type": "string",
      "maxLength": 200
    },
    "starter_key": {
      "type": [
        "string",
        "null"
      ],
      "maxLength": 100
    },
    "job_scope": {
      "type": "string",
      "enum": [
        "all_compatible",
        "selected"
      ]
    },
    "job_posting_ids": {
      "type": "array",
      "items": {
        "type": "string",
        "format": "uuid"
      }
    },
    "delivery_mode": {
      "type": "string",
      "enum": [
        "auto_send",
        "auto_draft_review"
      ]
    },
    "timing": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "immediate"
              ]
            }
          },
          "required": [
            "type"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "delay"
              ]
            },
            "delayMinutes": {
              "type": "integer",
              "minimum": 0
            }
          },
          "required": [
            "type",
            "delayMinutes"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "interview_relative"
              ]
            },
            "anchor": {
              "type": "string",
              "enum": [
                "start",
                "end"
              ]
            },
            "offsetMinutes": {
              "type": "integer"
            }
          },
          "required": [
            "type",
            "anchor",
            "offsetMinutes"
          ],
          "additionalProperties": false
        }
      ]
    },
    "pipeline_stage_id": {
      "type": [
        "string",
        "null"
      ],
      "minLength": 1
    },
    "trigger": {
      "type": "string",
      "enum": [
        "offer_signed",
        "stage_enter",
        "stage_exit",
        "step_ready",
        "booking_created",
        "booking_changed",
        "step_completed",
        "feedback_submitted",
        "all_scorecards_submitted",
        "interview_time",
        "assignment_changed",
        "hiring_manager_advanced",
        "hiring_manager_held",
        "booking_cancelled",
        "scorecard_due",
        "scorecard_overdue",
        "decision_brief_ready",
        "coaching_report_ready",
        "offer_approval_due",
        "offer_approval_escalation_due"
      ]
    },
    "action": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "move_to_hired_stage"
              ]
            }
          },
          "required": [
            "type"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "create_task"
              ]
            },
            "task_type": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200,
              "description": "Add to My Tasks: scorecard_review on feedback_submitted, or coordination for a general follow-up. Same-kind tasks are stacked."
            },
            "task_title": {
              "type": "string",
              "minLength": 1,
              "maxLength": 500,
              "description": "Task title; {candidate} resolves to the candidate name."
            },
            "assigned_user_email": {
              "type": "string",
              "minLength": 1,
              "maxLength": 320
            },
            "assigned_role": {
              "type": "string",
              "enum": [
                "assigned_interviewer",
                "recruiter",
                "hiring_manager",
                "team_owner"
              ]
            },
            "due_date": {
              "type": "string",
              "minLength": 1,
              "maxLength": 64,
              "description": "Existing fixed deadline; use due_in for recurring rules."
            },
            "due_in": {
              "type": "object",
              "properties": {
                "value": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 8760
                },
                "unit": {
                  "type": "string",
                  "enum": [
                    "days",
                    "hours"
                  ]
                }
              },
              "required": [
                "value",
                "unit"
              ],
              "additionalProperties": false,
              "description": "Due this many days or hours after the rule fires; at most 365 days or 8760 hours. Cannot combine with due_date."
            },
            "context": {
              "type": "object",
              "additionalProperties": {}
            }
          },
          "required": [
            "type",
            "task_type",
            "task_title"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "update_scheduling"
              ]
            },
            "template_key": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            },
            "delivery": {
              "type": "string",
              "enum": [
                "auto_send",
                "auto_draft_review"
              ],
              "default": "auto_draft_review"
            },
            "task": {
              "type": "object",
              "properties": {
                "assignee": {
                  "anyOf": [
                    {
                      "type": "string",
                      "enum": [
                        "recruiter"
                      ]
                    },
                    {
                      "type": "object",
                      "properties": {
                        "user_id": {
                          "type": "string",
                          "format": "uuid"
                        }
                      },
                      "required": [
                        "user_id"
                      ],
                      "additionalProperties": false
                    }
                  ]
                },
                "title": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 500
                },
                "due_in": {
                  "type": "object",
                  "properties": {
                    "value": {
                      "type": "integer",
                      "minimum": 1,
                      "maximum": 8760
                    },
                    "unit": {
                      "type": "string",
                      "enum": [
                        "days",
                        "hours"
                      ]
                    }
                  },
                  "required": [
                    "value",
                    "unit"
                  ],
                  "additionalProperties": false
                }
              },
              "required": [
                "assignee",
                "title"
              ],
              "additionalProperties": false
            }
          },
          "required": [
            "type",
            "task"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "send_email"
              ]
            },
            "email_type": {
              "type": "string",
              "enum": [
                "acknowledgment",
                "advancement",
                "interview_confirmation",
                "rejection",
                "offer_declined",
                "offer",
                "hired",
                "withdrawn",
                "on_hold",
                "interview_cancellation"
              ]
            },
            "template_key": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            },
            "sender_type": {
              "type": "string",
              "enum": [
                "owner",
                "job_hiring_manager"
              ],
              "description": "Who the email comes from: owner = the job's recruiter, job_hiring_manager = the job's hiring manager. Omit to use the company's sender setting for this email."
            }
          },
          "required": [
            "type"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "send_scheduling_invitation"
              ]
            },
            "interview_ids": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1
              }
            },
            "format": {
              "type": "string",
              "enum": [
                "combined",
                "separate"
              ]
            },
            "template_key": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            }
          },
          "required": [
            "type",
            "interview_ids",
            "format"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "send_preparation_email"
              ]
            },
            "template_key": {
              "type": "string",
              "enum": [
                "candidate_preparation",
                "onsite_logistics",
                "technical_preparation"
              ]
            }
          },
          "required": [
            "type"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "send_internal_email"
              ]
            },
            "audience": {
              "type": "string",
              "enum": [
                "assigned_interviewer",
                "recruiter",
                "hiring_manager",
                "team_owner",
                "offer_approver",
                "offer_requester"
              ]
            },
            "template": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            }
          },
          "required": [
            "type",
            "audience",
            "template"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "verify_calendar_event"
              ]
            }
          },
          "required": [
            "type"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "send_webhook"
              ]
            },
            "url": {
              "type": "string",
              "maxLength": 2048,
              "description": "Write-only HTTPS URL that receives a signed, IDs-only event. Only organization admins can set or change it; responses show it to admins as webhook.url and to others only as webhook.host. Omit to keep the current URL."
            }
          },
          "required": [
            "type"
          ],
          "additionalProperties": false
        }
      ]
    },
    "condition": {
      "type": "object",
      "properties": {
        "step_position": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "which": {
                  "type": "string",
                  "enum": [
                    "next"
                  ]
                }
              },
              "required": [
                "which"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "which": {
                  "type": "string",
                  "enum": [
                    "first"
                  ]
                },
                "kind": {
                  "type": "string",
                  "enum": [
                    "candidate_interview",
                    "reference_check",
                    "internal_debrief",
                    "offer_meeting"
                  ]
                }
              },
              "required": [
                "which",
                "kind"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "which": {
                  "type": "string",
                  "enum": [
                    "last"
                  ]
                },
                "kind": {
                  "type": "string",
                  "enum": [
                    "candidate_interview",
                    "reference_check",
                    "internal_debrief",
                    "offer_meeting"
                  ]
                }
              },
              "required": [
                "which",
                "kind"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "which": {
                  "type": "string",
                  "enum": [
                    "last_before"
                  ]
                },
                "kind": {
                  "type": "string",
                  "enum": [
                    "candidate_interview",
                    "reference_check",
                    "internal_debrief",
                    "offer_meeting"
                  ]
                },
                "anchor_kind": {
                  "type": "string",
                  "enum": [
                    "candidate_interview",
                    "reference_check",
                    "internal_debrief",
                    "offer_meeting"
                  ]
                }
              },
              "required": [
                "which",
                "kind",
                "anchor_kind"
              ],
              "additionalProperties": false
            }
          ]
        },
        "public_application_only": {
          "type": "boolean"
        },
        "interview_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "step_kinds": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": [
              "candidate_interview",
              "reference_check",
              "internal_debrief",
              "offer_meeting"
            ]
          },
          "minItems": 1
        },
        "recruiter_note": {
          "type": "boolean"
        }
      },
      "additionalProperties": true
    },
    "is_active": {
      "type": "boolean"
    },
    "position": {
      "type": [
        "integer",
        "null"
      ],
      "minimum": 0
    },
    "id": {
      "type": "string"
    },
    "object": {
      "type": "string",
      "enum": [
        "automation_rule"
      ]
    },
    "created_at": {
      "type": [
        "string",
        "null"
      ]
    },
    "updated_at": {
      "type": [
        "string",
        "null"
      ]
    }
  },
  "required": [
    "pipeline_template_id",
    "job_id",
    "needs_step_pick",
    "name",
    "starter_key",
    "job_scope",
    "job_posting_ids",
    "delivery_mode",
    "timing",
    "pipeline_stage_id",
    "trigger",
    "action",
    "condition",
    "is_active",
    "position",
    "id",
    "object",
    "created_at",
    "updated_at"
  ],
  "additionalProperties": false
}