import { useMutation } from 'react-query';

import { queryClient } from 'src/config/react-query';
import { deleteSession } from 'src/pages/dashboard/Learning/Sessions/services';
import { LogEvents, logEvent } from 'src/utils/logging';

import { sessionsKeys } from '../queries';

export const useDeleteSessionMutation = () => {
  return useMutation(deleteSession, {
    onSuccess: (_, sessionId) => {
      queryClient.invalidateQueries(sessionsKeys.sessions.all());
      queryClient.invalidateQueries(sessionsKeys.stats());
      logEvent(LogEvents.SESSION_DELETED, { sessionId });
    },
  });
};
