import { NextResponse } from 'next/server';

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

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