// Generated by bynkc — do not edit by hand.
// Worker entry point for context `greet`.

import { Ok, Err, type Result, type JsonValue, type BoundaryError, boundaryError } from "../../runtime.js";
import { compose, type Env } from "./compose.js";
import * as handlers from "./handlers.js";

export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    const url = new URL(request.url);
    const path = url.pathname;
    const method = request.method;
    const surface = compose(env);
    try {
      if (path.startsWith("/_bynk/call/")) {
        const servicePath = path.slice("/_bynk/call/".length);
        switch (servicePath) {
          case "hello": {
            const args = await request.json() as JsonValue;
            const __r_name = (typeof args === "string" ? Ok(args) : Err({ kind: "StructuralMismatch", path: "$", expected: "string", actual: typeof args }) as Result<any, BoundaryError>);
            if (__r_name.tag === "Err") return new Response(JSON.stringify(__r_name.error), { status: 400, headers: { "content-type": "application/json" } });
            const name = __r_name.value;
            const result = await surface.hello(name);
            const body = handlers.serialise_Result_String_Unit(result);
            return new Response(JSON.stringify(body), { status: 200, headers: { "content-type": "application/json" } });
          }
          default:
            return new Response("Not found", { status: 404 });
        }
      }

      return new Response("Not Found", { status: 404 });
    } catch {
      return new Response("Internal Server Error", { status: 500 });
    }
  },
};
