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

const CONTACT_PAGE_ID = BigInt(8); 

const serializeBigInt = (data: any) =>
  JSON.parse(
    JSON.stringify(data, (_, value) =>
      typeof value === "bigint" ? value.toString() : value
    )
  );

export async function GET() {
  try {
    const [contact, studios] = await Promise.all([
      prisma.cms_contact.findUnique({
        where: { page_id: CONTACT_PAGE_ID, status: true },
      }),
      prisma.cms_contact_studios.findMany({
        where: { page_id: CONTACT_PAGE_ID, status: true },
        orderBy: { sort_order: "asc" },
      }),
    ]);

    return NextResponse.json({
      success: true,
      data: {
        contact: contact ? serializeBigInt(contact) : null,
        studios: serializeBigInt(studios),
      },
    });
  } catch (error: any) {
    return NextResponse.json(
      { success: false, message: error.message || "Failed to fetch data" },
      { status: 500 }
    );
  }
}