import { useMutation, useQueryClient } from '@tanstack/react-query';

import { IssuesService } from '@/client/services/IssuesService';

export function useUnassignIssueLabel(workspaceName: string | null, number: number | null) {
  const qc = useQueryClient();

  return useMutation({
    mutationFn: (labelId: string) => {
      if (!workspaceName || number === null) throw new Error('Missing params');
      return IssuesService.issueUnassignLabel({ workspaceName, number, labelId });
    },
    onSuccess: () => {
      qc.invalidateQueries({
        queryKey: ['workspace', workspaceName, 'issues', number, 'labels'],
      });
    },
  });
}
