// Generated by bynkc — do not edit by hand.
// context greet

import { Ok, Err, Some, None, type Result, type Option, type ValidationError, type JsonValue, type BoundaryError, type ServiceBinding, callService, boundaryError } from "../../runtime.js";

export interface Clock {
  now(): Promise<number>;
}

export const ClockToken: unique symbol = Symbol("Clock");

export class FixedClock implements Clock {
  async now(): Promise<number> {
    return 42;
  }
}

export const FixedClockProvider = { token: ClockToken, factory: () => new FixedClock() };

export const hello = {
  async call(name: string, deps: { Clock: Clock }): Promise<Result<string, void>> {
    const n = await deps.Clock.now();
    return Ok("hello");
  },
};

export function serialise_Result_String_Unit(value: Result<string, void>): JsonValue {
  if (value.tag === "Ok") return { kind: "Ok", value: value.value as JsonValue };
  return { kind: "Err", error: null };
}

export function deserialise_Result_String_Unit(json: JsonValue, path: string = "$"): Result<Result<string, void>, BoundaryError> {
  if (typeof json !== "object" || json === null || Array.isArray(json)) {
    return Err({ kind: "StructuralMismatch", path, expected: "object", actual: typeof json });
  }
  const obj = json as { [k: string]: JsonValue };
  if (obj["kind"] === "Ok") {
  if (typeof obj["value"] !== "string") {
    return Err({ kind: "StructuralMismatch", path: `${path}.value`, expected: "string", actual: typeof obj["value"] });
  }
  const __v = obj["value"];
    return Ok(Ok(__v) as Result<string, void>);
  } else if (obj["kind"] === "Err") {
  const __e = undefined;
    return Ok(Err(__e) as Result<string, void>);
  }
  return Err({ kind: "StructuralMismatch", path, expected: "Ok | Err", actual: String(obj["kind"]) });
}

