import { NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";

/** Public: the GA4 measurement ID for site-wide visitor tracking
    (consumed by the gtag loader in the root layout). No secrets here —
    measurement IDs are public by design. */
export async function GET() {
  const row = await prisma.analyticsSetting.findFirst({
    where: { scope: "CENTRAL", active: true, measurementId: { not: null } },
    orderBy: { id: "asc" },
    select: { measurementId: true },
  });
  return NextResponse.json({ measurementId: row?.measurementId ?? null });
}
