import { NextRequest, NextResponse } from "next/server";
import { sendToQueue } from "@/app/utils/sqs";

export async function POST(req: NextRequest) {
  try {
    const { id } = await req.json();

    if (!id) {
      return NextResponse.json({ error: "Missing id" }, { status: 400 });
    }

    const resp = await sendToQueue({ id }, { queueName: "extractor-loader-queue" });

    return NextResponse.json(
      { ok: true, messageId: resp.MessageId },
      { status: 200 }
    );
  } catch (err: any) {
    console.error("SQS enqueue failed:", err);
    return NextResponse.json({ error: err.message }, { status: 500 });
  }
}