import { NextResponse } from 'next/server';

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

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