import { NextResponse } from "next/server";

/**
 * GET /api/confirm/{id}?token=xxx
 * 
 * Redirects to the confirm page with the token in the URL.
 * This is the link sent in WhatsApp messages.
 * The actual confirmation logic is in /api/confirm/{id}/action (POST).
 */
export async function GET(
  req: Request,
  { params }: { params: Promise<{ id: string }> }
) {
  const { id } = await params;
  const baseUrl = process.env.NEXT_PUBLIC_APP_URL || new URL(req.url).origin;
  const url = new URL(req.url);
  const token = url.searchParams.get("token") || "";

  // Redirect to the confirm page with token as query param
  return NextResponse.redirect(`${baseUrl}/confirm/${id}?token=${token}`);
}
