# `AshWorkflow.Transformers.AddStateMachine`
[🔗](https://github.com/team-alembic/ash_workflow/blob/v0.12.0/lib/ash_workflow/transformers/add_state_machine.ex#L1)

Generates ash_state_machine configuration from workflow steps.

Injects the following into the resource's `state_machine` DSL:

- **`state_attribute`** — the workflow's `state_attribute`, when it declares one.
- **`initial_states`** — set to the step with `initial: true`, or the first
  non-terminal step by declaration order if none is marked.
- **`default_initial_state`** — same as above
- **Transitions** for each step type:
  - *Automatic steps* — `transition :step_action, from: [:step_name], to: [...]`, where
    `to` is every target across the step's `on_success` entries.
    If `on_error` is set, a transition named `__on_error_<step>` to the error
    state is added — declared on the error handler action rather than on the
    step's own action, since that is what AshOban invokes when the step fails.
  - *Manual steps* — one transition per declared `transition` entity,
    e.g. `transition :approve, from: [:review], to: [:approved]`
  - *Undoable transitions* — when the workflow declares an `undo` block, two
    `:undo` transitions per undoable edge, one in each direction, so both a
    rewind and a subsequent redo are permitted.
  - *Timeouts with `transition_to`* — a transition named `__timeout_<step>_<name>`,
    e.g. `transition :__timeout_review_escalation, from: [:review], to: [:escalated]`
  - *`on_signal` with `transition_to`* — a transition named `__signal_<step>_<signal>`,
    e.g. `transition :__signal_awaiting_payment_payment_settled, from: [:awaiting_payment], to: [:fulfilling]`

Must run before all `AshStateMachine.Transformers.*` so that the state machine
extension sees the generated states and transitions.

# `after?`

# `after_compile?`

# `before?`

# `transform`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
