import { usePrisma } from "../../utils/prisma";

/**
 * GET /api/blocklist/check?domain=example.com
 * Returns { inGlobal: boolean }
 */
export default defineEventHandler(async (event) => {
  await requireUser(event);
  const { domain } = getQuery(event) as { domain?: string };
  if (!domain)
    throw createError({ statusCode: 400, message: "domain required" });

  const db = usePrisma();
  const row = await db.blocklistDomain.findFirst({
    where: { domain: domain.toLowerCase().trim(), isActive: true },
    select: { domain: true },
  });
  return { inGlobal: !!row };
});
