// app/api/challenges/pending/route.ts
;
import { NextResponse } from "next/server";

import { prisma } from '@/lib/prisma';

export async function GET() {
    try {
        const pendingChallenges = await prisma.userProduct.findMany({
            where: {
                challengeStatus: "PENDING"
            },
            select: {
                id: true,
                productId: true,
                createdAt: true,
                product: {
                    select: {
                        plan: true,
                        description: true
                    }
                }
            }
        });

        return NextResponse.json(pendingChallenges);
    } catch (error) {
        console.error("Error fetching pending challenges:", error);
        return new NextResponse("Internal Error", { status: 500 });
    }
}