import { NextRequest } from "next/server";

import { proxyHermesRequest } from "@/lib/server/hermes-proxy";
import { assertSameOrigin } from "@/lib/server/request-guards";

type Params = {
  params: Promise<{
    id: string;
  }>;
};

async function proxyRepairRequest(request: NextRequest, { params }: Params) {
  const { id } = await params;
  return proxyHermesRequest(request, `/repairs/${id}`);
}

export async function GET(request: NextRequest, context: Params) {
  return proxyRepairRequest(request, context);
}

export async function PUT(request: NextRequest, context: Params) {
  const originError = assertSameOrigin(request);

  if (originError) {
    return originError;
  }

  return proxyRepairRequest(request, context);
}

export async function DELETE(request: NextRequest, context: Params) {
  const originError = assertSameOrigin(request);

  if (originError) {
    return originError;
  }

  return proxyRepairRequest(request, context);
}
