context commerce.payment {
  exports opaque { AuthId }
  exports transparent { PaymentError }

  type AuthId = opaque String
  type PaymentError = | Declined | InsufficientFunds

  capability Logger {
    fn log(msg: String) -> Effect[()]
  }

  provides Logger = ConsoleLogger {
    fn log(msg: String) -> Effect[()] {
      ()
    }
  }

  service authorise {
    on call(amount: Int) -> Effect[Result[AuthId, PaymentError]] given Logger {
      let _ <- Logger.log("authorise")
      if amount == 0 {
        Err(Declined)
      } else if amount > 1000000 {
        Err(InsufficientFunds)
      } else {
        Ok(AuthId.unsafe("AUTH-DEFAULT"))
      }
    }
  }
}
