import { NextResponse } from "next/server";
import { getCurrentUser } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
export const dynamic = "force-dynamic";
export async function DELETE(_req: Request, { params }: { params: Promise<{ id: string }> }) {
  const user = await getCurrentUser();
  if (!user) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
  const { id } = await params;
  // Get the query text before deleting so we can clean up check results
  const query = await prisma.aiVisibilityQuery.findUnique({ where: { id }, select: { query: true, brandId: true } });
  await prisma.aiVisibilityQuery.delete({ where: { id } });
  // Also remove cached check results for this query
  if (query) {
    await prisma.aiVisibilityCheck.deleteMany({ where: { brandId: query.brandId, query: query.query } });
  }
  return NextResponse.json({ ok: true });
}
