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

export async function GET() {
  try {
    const designs = await prisma.designApproval.findMany({
      where: { status: 'PENDING' },
      include: { product: true, messages: { orderBy: { createdAt: 'desc' }, take: 1 } },
      orderBy: { createdAt: 'desc' },
    });

    return NextResponse.json(designs);
  } catch (err) {
    console.error('Error fetching pending designs:', err);
    return NextResponse.json(
      { error: 'Failed to fetch pending designs' },
      { status: 500 }
    );
  }
}
