// 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_case_one() {
  try {
    const deps = makeTestDeps();
    const { AuthId, PaymentError, authorise } = commerce_payment as any;
    const r = await authorise.call(10, deps);
    if (!(r.tag === "Ok")) { throw __bynkAssertionFailure("tests/payment.test.bynk:10:12", 179, 189); }
    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_case_two() {
  try {
    const deps = makeTestDeps();
    const { AuthId, PaymentError, authorise } = commerce_payment as any;
    const r = await authorise.call(20, deps);
    if (!(r.tag === "Ok")) { throw __bynkAssertionFailure("tests/payment.test.bynk:15:12", 258, 268); }
    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_case_three() {
  try {
    const deps = makeTestDeps();
    const { AuthId, PaymentError, authorise } = commerce_payment as any;
    const r = await authorise.call(0, deps);
    if (!(r.tag === "Err")) { throw __bynkAssertionFailure("tests/payment.test.bynk:20:12", 338, 349); }
    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: "case one", ...(await test_case_one()) });
  results.push({ name: "case two", ...(await test_case_two()) });
  results.push({ name: "case three", ...(await test_case_three()) });
  return results;
}
