// Generated by bynkc — do not edit by hand.
// composition root for `api` Worker.

import { type ServiceBinding, HttpResult, verifyBearerJwtHs256 } from "../../runtime.js";
import * as handlers from "./handlers.js";

export interface Env {
}

export function compose(env: Env) {
  const deps = {  };
  return {
    async http_GET_notes_Param_id(request: Request, id: any) {
      let __who: any = undefined;
      if (__who === undefined) {
        const __authz = request.headers.get("Authorization");
        if (__authz !== null && __authz.startsWith("Bearer ")) {
          const __secret = (env as Record<string, unknown>)["AUTH_JWT_SECRET"] ?? (globalThis as { process?: { env?: Record<string, unknown> } }).process?.env?.["AUTH_JWT_SECRET"];
          if (typeof __secret === "string") {
            const __claims = await verifyBearerJwtHs256(__authz.slice(7), __secret);
            if (__claims.tag === "Ok") {
              const __id = handlers.UserId.of(__claims.value.sub);
              if (__id.tag === "Ok") __who = { tag: "User", identity: __id.value };
            }
          }
        }
      }
      if (__who === undefined) {
        __who = { tag: "Visitor" };
      }
      if (__who === undefined) return HttpResult.Unauthorized;
      return handlers.api.http_GET_notes_Param_id(id, { ...deps, who: __who });
    },
  };
}
