(require '[boundary.workflow.core.machine :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"}}
:hooks {:on-enter-paid (fn [instance] (notify-finance! instance))
:on-any-transition (fn [instance] (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]}]})