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

// TODO: replace with the actual id of the About Us row in cms_pages
const ABOUT_PAGE_ID = BigInt(2);

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

export async function GET() {
  try {
    const data = await prisma.cms_about.findFirst({
      where: {
        page_id: ABOUT_PAGE_ID,
        status: true,
      },
    });

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