// Generated by bynkc — do not edit by hand.
// context commerce.payment

import { Ok, Err, Some, None, type Result, type Option, type ValidationError } from "../runtime.js";

import { Money as __CommonsMoney } from "./money.js";

export type Money = __CommonsMoney & { readonly __ctxBrand: "commerce.payment" };

export type Token = string & { readonly __brand: "commerce.payment.Token" };

export const Token = {
  of(value: string): Result<Token, ValidationError> {
    if (!new RegExp("^" + "T-[0-9]+" + "$").test(value)) {
      return Err({ field: "Token", message: "must match /T-[0-9]+/", value });
    }
    return Ok(value as Token);
  },
  unsafe(value: string): Token {
    return value as Token;
  },
};

export const authorise = {
  async call(amount: Money, deps: {}): Promise<Result<Token, number>> {
    return Ok(Token.unsafe("T-1"));
  },
};

export interface CommercePaymentDeps {
}

export function makeSurface(deps: CommercePaymentDeps) {
  return {
    async authorise(amount: Money): Promise<Result<Token, number>> {
      return authorise.call(amount, deps);
    },
  };
}

