context demo.order

type AuthId = String where NonEmpty
type OrderStatus = enum { Pending, Paid }

agent Order {
  key id: String

  store status: Cell[OrderStatus] = Pending
  store paymentRef: Cell[Option[AuthId]]

  invariant paid_has_payment_ref:
    status == Paid implies paymentRef.isSome()

  on call pay(ref: AuthId) -> Effect[()] {
    status := Paid
    paymentRef := Some(ref)
    ()
  }
}
