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

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

class AssertionError extends Error {
  constructor(public location: string, public start: number, public end: number) {
    super(`assertion failed at ${location}`);
  }
}
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); }
}

function makeTestDeps() {
  return {  };
}

async function test_agent_place_reports_Ok() {
  try {
    commerce_orders.__resetAgents();
    const deps = makeTestDeps();
    const { Order, OrderError, OrderId, __makeOrder } = commerce_orders as any;
    const r = await __makeOrder(OrderId.unsafe("ORD-1")).place(50, deps);
    if (!(r.tag === "Ok")) { throw __bynkAssertionFailure("offset 122", 122, 132); }
    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_agent_place_reports_NotPlaced_for_zero() {
  try {
    commerce_orders.__resetAgents();
    const deps = makeTestDeps();
    const { Order, OrderError, OrderId, __makeOrder } = commerce_orders as any;
    const r = await __makeOrder(OrderId.unsafe("ORD-2")).place(0, deps);
    if (!(r.tag === "Err")) { throw __bynkAssertionFailure("offset 252", 252, 263); }
    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: "agent place reports Ok", ...(await test_agent_place_reports_Ok()) });
  results.push({ name: "agent place reports NotPlaced for zero", ...(await test_agent_place_reports_NotPlaced_for_zero()) });
  return results;
}
