import { NextResponse } from 'next/server';

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

export const PATCH = withAuth(async (_req, ctx, params) => {
  try {
    const { notificationId } = params;
    if (!notificationId) throw new NotFoundError('Notification');
    await notificationsService.markRead(notificationId, ctx.userId);
    return new NextResponse(null, { status: 204 });
  } catch (error) {
    return errorResponse(error);
  }
});
