// 사용자 비활성화 (status='inActive') — 데이터 보존
import { NextRequest, NextResponse } from "next/server";
import { execute } from "@/lib/db";
import { getSession } from "@/lib/session";

export async function POST(req: NextRequest) {
  const user = await getSession();
  if (!user) return NextResponse.json({ success: false }, { status: 401 });
  const { ids, userIds, activate } = await req.json() as {
    ids?: string[]; userIds?: string[]; activate?: boolean;
  };
  const targets = (userIds || ids || []).filter(Boolean);
  if (targets.length === 0) {
    return NextResponse.json({ success: false, message: "대상 사용자를 선택하세요." }, { status: 400 });
  }
  const placeholders = targets.map((_, i) => `$${i + 1}`).join(",");
  const newStatus = activate ? "active" : "inActive";
  await execute(`UPDATE user_info SET status=$${targets.length + 1} WHERE user_id IN (${placeholders})`, [...targets, newStatus]);
  return NextResponse.json({ success: true, count: targets.length, status: newStatus });
}
