// Generated by bynkc — do not edit by hand.
// test target: demo.registry

import { Ok, Err, Some, None, type Result, type Option, type ValidationError } from "../runtime.js";
import * as demo_registry from "./../demo/registry.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); }
}

class TestClock {
  async now(): Promise<number> {
    const { Code, RegError, Target } = demo_registry as any;
    return 7;
  }
}

function makeTestDeps() {
  return { Clock: new TestClock() };
}

async function test_create_accepts_two_args_and_threads_deps() {
  try {
    const deps = makeTestDeps();
    const { Code, RegError, Target, create } = demo_registry as any;
    void (await (async (__d) => {
        switch (__d.tag) {
          case "Err": {
            return __bynkAssert((false), "offset 285", 285, 290);
          }
          case "Ok": {
            const code = __d.value;
            return await (async (__d) => {
        switch (__d.tag) {
          case "Err": {
            return __bynkAssert((false), "offset 366", 366, 371);
          }
          case "Ok": {
            const target = __d.value;
            const outcome = await create.call(code, target, deps);
            switch (outcome.tag) {
              case "Ok": {
                const t = outcome.value;
                return __bynkAssert((t === 7), "offset 478", 478, 484);
              }
              case "Err": {
                return __bynkAssert((false), "offset 507", 507, 512);
              }
            }
            throw new Error("non-exhaustive match");
          }
        }
        throw new Error("non-exhaustive match");
      })(Target.of("https://example.com"));
          }
        }
        throw new Error("non-exhaustive match");
      })(Code.of("abc123")));
    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: "create accepts two args and threads deps", ...(await test_create_accepts_two_args_and_threads_deps()) });
  return results;
}
