(require '[wagoe.workflow.shell.registry :refer [defworkflow]])
(defworkflow order-workflow
{:id :order-workflow
:initial-state :pending
:description "E-commerce order lifecycle"
:states #{:pending :paid :shipped :delivered :cancelled}
:state-config {:pending {:label "Awaiting Payment"}
:paid {:label "Payment Received"}
:shipped {:label "In Transit"}
:delivered {:label "Delivered"}
:cancelled {:label "Cancelled"}}
;; Each hook is a vector of fns of [instance audit-entry context].
:hooks {:on-enter-paid [(fn [instance _audit-entry _context]
(notify-finance! instance))]
:on-any-transition [(fn [instance _audit-entry _context]
(sync-external! instance))]}
:transitions [{:from :pending :to :paid
:label "Mark as Paid"
:required-permissions [:finance :admin]}
{:from :paid :to :shipped
:guard :payment-confirmed}
{:from :shipped :to :delivered
:label "Confirm Delivery"}
{:from :pending :to :cancelled
:auto? true
:side-effects [:notify-cancellation]}]
:guards {:payment-confirmed (fn [{:keys [payment-status]}]
(= :confirmed payment-status))}})