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

export async function GET() {
  try {
    const whyRKDAData = await prisma.cms_why_rkda.findMany({
      where: {
        status: true,
      },
      orderBy: {
        sort_order: "asc",
      },
    });

    // Convert BigInt values to strings
    const data = JSON.parse(
      JSON.stringify(whyRKDAData, (_, value) =>
        typeof value === "bigint" ? value.toString() : value
      )
    );

    return NextResponse.json(data, {
      status: 200,
      headers: {
        "Cache-Control": "no-store",
      },
    });
  } catch (error) {
    console.error("Error fetching Why RKDA:", error);

    return NextResponse.json(
      {
        success: false,
        message: "Failed to fetch Why RKDA data",
        error: error instanceof Error ? error.message : String(error),
      },
      { status: 500 }
    );
  }
}