import { NextRequest, NextResponse } from "next/server";
import { execute } from "@/lib/db";
import { requireMomoAdmin } from "@/lib/momo-guard";

export async function POST(req: NextRequest) {
  const g = await requireMomoAdmin();
  if (g instanceof NextResponse) return g;

  const { objids } = await req.json();
  if (!Array.isArray(objids) || objids.length === 0) {
    return NextResponse.json({ success: false, message: "삭제할 항목이 없습니다." }, { status: 400 });
  }

  const placeholders = objids.map((_, i) => `$${i + 1}`).join(",");
  await execute(
    `UPDATE momo_items SET is_del='Y', update_date=NOW() WHERE objid IN (${placeholders})`,
    objids
  );
  return NextResponse.json({ success: true });
}
