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

const SUPPORT_US_PAGE_ID = BigInt(7);

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

// GET: public — only active sections, ordered for display
export async function GET() {
  try {
    const data = await prisma.cms_support_us_sections.findMany({
      where: { page_id: SUPPORT_US_PAGE_ID, status: true },
      orderBy: [{ sort_order: "asc" }, { id: "asc" }],
    });

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