import { NextResponse } from 'next/server';

import { withPortalAuth } from '@/lib/portal/helpers';
import { getClientDocuments } from '@/lib/services/portal.service';
import { logger } from '@/lib/logger';

export const GET = withPortalAuth(async (_req, session) => {
  try {
    const data = await getClientDocuments(session.clientId, session.portId);
    return NextResponse.json({ data });
  } catch (error) {
    logger.error({ error }, 'Portal documents fetch failed');
    return NextResponse.json({ error: 'Failed to load documents' }, { status: 500 });
  }
});
