import { NextResponse } from 'next/server';

import { withAuth, withPermission } from '@/lib/api/helpers';
import { getReport } from '@/lib/services/reports.service';
import { errorResponse } from '@/lib/errors';

export const GET = withAuth(
  withPermission('reports', 'view_dashboard', async (_req, ctx, params) => {
    try {
      const reportId = params.id ?? '';
      const report = await getReport(reportId, ctx.portId);
      return NextResponse.json({ data: report });
    } catch (error) {
      return errorResponse(error);
    }
  }),
);
