import { NextResponse } from 'next/server';

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

export const POST = withAuth(
  withPermission('clients', 'edit', async (req, ctx, params) => {
    try {
      await restoreClient(params.id!, ctx.portId, {
        userId: ctx.userId,
        portId: ctx.portId,
        ipAddress: ctx.ipAddress,
        userAgent: ctx.userAgent,
      });
      return NextResponse.json({ success: true });
    } catch (error) {
      return errorResponse(error);
    }
  }),
);
