// Generated by bynkc — do not edit by hand.
// integration test: jobs use the clock

import { Ok, Err, Some, None, callService, type Result, type Option, type ValidationError, type JsonError, type JsonValue, type BoundaryError, type ServiceBinding } from "../runtime.js";
import * as ops_jobs from "../workers/ops-jobs/handlers.js";
import worker_ops_jobs from "../workers/ops-jobs/index.js";
import * as platform_time from "../workers/platform-time/handlers.js";
import worker_platform_time from "../workers/platform-time/index.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 makeHarness() {
  const env_ops_jobs: any = {};
  const env_platform_time: any = {};
  env_ops_jobs.PLATFORM_TIME = { fetch: (req: Request) => worker_platform_time.fetch(req, env_platform_time) } as ServiceBinding;
  const rootEnv: any = {};
  rootEnv.OPS_JOBS = { fetch: (req: Request) => worker_ops_jobs.fetch(req, env_ops_jobs) } as ServiceBinding;
  rootEnv.PLATFORM_TIME = { fetch: (req: Request) => worker_platform_time.fetch(req, env_platform_time) } as ServiceBinding;
  return { env: rootEnv };
}

async function test_tick_reads_the_clock_and_succeeds() {
  try {
    const deps = makeHarness();
    const r = await callService(deps.env.OPS_JOBS, "tick", {  }, ops_jobs.deserialise_Result_Int_TickError, "integration");
    if (!(r.tag === "Ok")) { throw __bynkAssertionFailure("offset 364", 364, 374); }
    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: "tick reads the clock and succeeds", ...(await test_tick_reads_the_clock_and_succeeds()) });
  return results;
}
