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

export async function GET() {
  const unassigned = await prisma.contact.findMany({
    where: { status: "UNASSIGNED" },
    orderBy: { createdAt: "desc" },
    include: {
      messages: {
        orderBy: { sentAt: "asc" },
        include: { attachments: true },
      },
    },
  });
  return NextResponse.json(unassigned);
}
