/**
 * GET /api/brands/[brandId]/has-site-tag-data
 * Returns { has: true/false } based on actual SiteEvent/PageRecord data.
 */
import { NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";

export const dynamic = "force-dynamic";

export async function GET(_req: Request, { params }: { params: Promise<{ brandId: string }> }) {
  const { brandId } = await params;
  const d30 = new Date(Date.now() - 30 * 86400000);
  const [events, pages] = await Promise.all([
    prisma.siteEvent.count({ where: { brandId, timestamp: { gte: d30 } }, take: 1 }).catch(() => 0),
    prisma.pageRecord.count({ where: { brandId }, take: 1 }).catch(() => 0),
  ]);
  return NextResponse.json({ has: events > 0 || pages > 0 });
}
