// Generated by bynkc — do not edit by hand.
// test target: commerce.payment

import { Ok, Err, Some, None, type Result, type Option, type ValidationError } from "../runtime.js";
import * as commerce_payment from "./../commerce/payment.js";

class AssertionError extends Error {
  location: string;
  start: number;
  end: number;
  constructor(location: string, start: number, end: number) {
    super(`assertion failed at ${location}`);
    this.location = location;
    this.start = start;
    this.end = end;
  }
}
function __bynkAssertionFailure(location: string, start: number, end: number) {
  return new AssertionError(location, start, end);
}
function __bynkAssert(cond: boolean, location: string, start: number, end: number): void {
  if (!cond) { throw __bynkAssertionFailure(location, start, end); }
}

class SilentLogger {
  async log(msg: string): Promise<void> {
    const { AuthId, PaymentError } = commerce_payment as any;
    return undefined;
  }
}

function makeTestDeps() {
  return { Logger: new SilentLogger() };
}

async function test_authorise_returns_Ok_for_a_small_positive_amount() {
  try {
    const deps = makeTestDeps();
    const { AuthId, PaymentError, authorise } = commerce_payment as any;
    const result = await authorise.call(100, deps);
    if (!(result.tag === "Ok")) { throw __bynkAssertionFailure("tests/payment.test.bynk:10:12", 225, 240); }
    return { pass: true };
  } catch (e) {
    if (e instanceof AssertionError) {
      return { pass: false, error: { message: e.message, location: e.location } };
    }
    return { pass: false, error: { message: String(e), location: "unknown" } };
  }
}

async function test_authorise_returns_Err_Declined__for_zero() {
  try {
    const deps = makeTestDeps();
    const { AuthId, PaymentError, authorise } = commerce_payment as any;
    const result = await authorise.call(0, deps);
    void (((__d) => {
        switch (__d.tag) {
          case "Err": {
            const Declined = __d.error;
            if (!(true)) { throw __bynkAssertionFailure("tests/payment.test.bynk:16:33", 385, 389); }
            return undefined;
          }
          default: {
            if (!(false)) { throw __bynkAssertionFailure("tests/payment.test.bynk:17:33", 424, 429); }
            return undefined;
          }
        }
        throw new Error("non-exhaustive match");
      })(result));
    return { pass: true };
  } catch (e) {
    if (e instanceof AssertionError) {
      return { pass: false, error: { message: e.message, location: e.location } };
    }
    return { pass: false, error: { message: String(e), location: "unknown" } };
  }
}

async function test_authorise_returns_Err_InsufficientFunds__for_large_amounts() {
  try {
    const deps = makeTestDeps();
    const { AuthId, PaymentError, authorise } = commerce_payment as any;
    const result = await authorise.call(2000000, deps);
    void (((__d) => {
        switch (__d.tag) {
          case "Err": {
            const InsufficientFunds = __d.error;
            if (!(true)) { throw __bynkAssertionFailure("tests/payment.test.bynk:24:42", 615, 619); }
            return undefined;
          }
          default: {
            if (!(false)) { throw __bynkAssertionFailure("tests/payment.test.bynk:25:42", 663, 668); }
            return undefined;
          }
        }
        throw new Error("non-exhaustive match");
      })(result));
    return { pass: true };
  } catch (e) {
    if (e instanceof AssertionError) {
      return { pass: false, error: { message: e.message, location: e.location } };
    }
    return { pass: false, error: { message: String(e), location: "unknown" } };
  }
}

export async function run() {
  const results = [];
  results.push({ name: "authorise returns Ok for a small positive amount", ...(await test_authorise_returns_Ok_for_a_small_positive_amount()) });
  results.push({ name: "authorise returns Err(Declined) for zero", ...(await test_authorise_returns_Err_Declined__for_zero()) });
  results.push({ name: "authorise returns Err(InsufficientFunds) for large amounts", ...(await test_authorise_returns_Err_InsufficientFunds__for_large_amounts()) });
  return results;
}
