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

import { Ok, Err, type Result, type JsonValue, type BoundaryError, boundaryError, matchPath, httpResultToResponse } 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) {
          default:
            return new Response("Not found", { status: 404 });
        }
      }

      {
        const __m = matchPath("/orders/:id", path);
        if (method === "GET" && __m) {
          const __raw_id = __m.params["id"];
          const __r_id = handlers.OrderId.of(__raw_id);
          if (__r_id.tag === "Err") return new Response(JSON.stringify({ kind: "RefinementViolation", path: "path.id", violation: __r_id.error }), { status: 400, headers: { "content-type": "application/json" } });
          const id = __r_id.value;
          const result = await surface.http_GET_orders_Param_id(id);
          return httpResultToResponse(result, (v: any) => v as JsonValue);
        }
      }
      return new Response("Not Found", { status: 404 });
    } catch {
      return new Response("Internal Server Error", { status: 500 });
    }
  },
};
