// Generated by bynkc — do not edit by hand.
// context demo.svc

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

export type AuthId = string & { readonly __brand: "demo.svc.AuthId" };

export const AuthId = {
  of(value: string): Result<AuthId, ValidationError> {
    return Ok(value as AuthId);
  },
  unsafe(value: string): AuthId {
    return value as AuthId;
  },
};

export type PaymentError =
    { readonly tag: "Declined" }
  | { readonly tag: "InsufficientFunds" };

export const PaymentError = {
  Declined: { tag: "Declined" } as PaymentError,
  InsufficientFunds: { tag: "InsufficientFunds" } as PaymentError,
};

export const authorise = {
  async call(amount: number, deps: {}): Promise<Result<AuthId, PaymentError>> {
    return (amount === 0 ? Err(PaymentError.Declined) : (amount > 1000000 ? Err(PaymentError.InsufficientFunds) : Ok(AuthId.unsafe("AUTH-DEFAULT"))));
  },
};

export interface DemoSvcDeps {
}

export function makeSurface(deps: DemoSvcDeps) {
  return {
    async authorise(amount: number): Promise<Result<AuthId, PaymentError>> {
      return authorise.call(amount, deps);
    },
  };
}

