import { NextResponse } from 'next/server';

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

export const POST = withAuth(
  withPermission('reminders', 'edit_own', async (_req, ctx, params) => {
    try {
      const data = await completeReminder(params.id!, ctx.portId, {
        userId: ctx.userId,
        portId: ctx.portId,
        ipAddress: ctx.ipAddress,
        userAgent: ctx.userAgent,
      });
      return NextResponse.json({ data });
    } catch (error) {
      return errorResponse(error);
    }
  }),
);
