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

import { eventsQueryKeys } from '../events-query-keys';
import { type PostJoinEvent, eventsApi } from '../events-api';

import type { BaseAxiosError } from '../../../../types';
import { ResponseType } from '@api/response-type';

export const usePostUnjoinEventMutation = () => {
  return useMutation<ResponseType, BaseAxiosError, PostJoinEvent, ResponseType>({
    mutationKey: eventsQueryKeys.unjoinEvent(),
    mutationFn: async (data) => {
      const response = await eventsApi.unjoinEvent(data);
      return response.data;
    }
  });
};
