import { NextResponse } from "next/server";
import { getCurrentUser } from "@/lib/auth";
import { suggestQueries } from "@/lib/services/ai-visibility-checker";
export const dynamic = "force-dynamic";
export const maxDuration = 30;
export async function POST(req: Request) {
  const user = await getCurrentUser();
  if (!user) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
  const body = await req.json().catch(() => null);
  if (!body?.brandId) return NextResponse.json({ error: "brandId required" }, { status: 400 });
  const type = body.type === "nonbranded" ? "nonbranded" : "branded";
  const suggestions = await suggestQueries(body.brandId, type);
  // Return both the flat string list (backwards compat) and the rich objects
  return NextResponse.json({ queries: suggestions.map((s) => s.query), suggestions, type });
}
