import { NextResponse } from "next/server";
import { getServerSession } from "next-auth";
import { authOptions } from "@/app/api/auth/[...nextauth]/route";
import { documentRepository } from "@/lib/repositories/documentRepository";

/** Historial de intentos rechazados exclusivamente por duplicidad. */
export async function GET() {
  const session = await getServerSession(authOptions);
  if (!session?.user) return NextResponse.json({ error: "No autenticado" }, { status: 401 });

  try {
    const rejections = await documentRepository.findDuplicateRejections(session.user.id, session.user.role);
    return NextResponse.json({ success: true, rejections });
  } catch {
    return NextResponse.json({ error: "No se pudo cargar el historial de duplicados." }, { status: 500 });
  }
}
