import { NextResponse } from 'next/server';

import { withAuth } from '@/lib/api/helpers';
import { errorResponse } from '@/lib/errors';
import * as notificationsService from '@/lib/services/notifications.service';

export const GET = withAuth(async (_req, ctx) => {
  try {
    const result = await notificationsService.getUnreadCount(ctx.userId, ctx.portId);
    // L34 carve-out: deliberate bare-shape response (NOT the `{ data }`
    // envelope). The bell badge reads `count` off the JSON root; wrapping
    // it would break the consumer. Left as-is.
    return NextResponse.json(result);
  } catch (error) {
    return errorResponse(error);
  }
});
