import { NextRequest, NextResponse } from 'next/server';

import { withAuth, withPermission } from '@/lib/api/helpers';
import { getRecentActivity } from '@/lib/services/dashboard.service';

export const GET = withAuth(
  withPermission('reports', 'view_dashboard', async (req: NextRequest, ctx) => {
    const result = await getRecentActivity(ctx.portId);
    // L34 carve-out: deliberate bare-shape response (NOT the `{ data }`
    // envelope). The dashboard widgets read these fields off the root of
    // the JSON; wrapping them would break the consumers. Left as-is.
    return NextResponse.json(result);
  }),
);
