import { NextResponse } from 'next/server';

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

export const DELETE = withAuth(
  withPermission('clients', 'edit', async (req, ctx, params) => {
    try {
      await deleteRelationship(params.relId!, params.id!, ctx.portId, {
        userId: ctx.userId,
        portId: ctx.portId,
        ipAddress: ctx.ipAddress,
        userAgent: ctx.userAgent,
      });
      return new NextResponse(null, { status: 204 });
    } catch (error) {
      return errorResponse(error);
    }
  }),
);
