import { useMutation } from 'react-query';

import { startSurveyTask } from '../services';
import { type JourneyTaskDetail } from '../types';
import { invalidateJourneyStepTasksQueries } from '../utils';

export const useStartSurveyTask = (
  task?: JourneyTaskDetail,
  onSuccess?: () => void,
) => {
  return useMutation({
    mutationFn: (taskId: number) => startSurveyTask(taskId),
    onSuccess: () => {
      invalidateJourneyStepTasksQueries(task);
      onSuccess?.();
    },
  });
};
