import { NextResponse } from 'next/server';

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

export const GET = withAuth(
  withPermission('documents', 'view', async (_req, ctx) => {
    try {
      const counts = await getHubTabCounts(ctx.portId, ctx.user.email);
      return NextResponse.json({ data: counts });
    } catch (error) {
      return errorResponse(error);
    }
  }),
);
