import { NextResponse } from 'next/server';

import { withAuth } from '@/lib/api/helpers';
import { errorResponse, ValidationError } from '@/lib/errors';
import { acknowledgeAlert } from '@/lib/services/alerts.service';

export const POST = withAuth(async (_req, ctx, params) => {
  try {
    const id = params.id;
    if (!id) throw new ValidationError('id is required');
    await acknowledgeAlert(id, ctx.portId, ctx.userId);
    return NextResponse.json({ ok: true });
  } catch (error) {
    return errorResponse(error);
  }
});
