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

import { tripsQueryKeys } from '../trips-query-keys';
import { type PostSetNewTripReturn, type PostSetNewTrip, tripsApi } from '../trips-api';

import type { BaseAxiosError } from '../../../../types';

export const usePostSetNewTripMutation = () => {
  return useMutation<PostSetNewTripReturn, BaseAxiosError, PostSetNewTrip, PostSetNewTripReturn>({
    mutationKey: tripsQueryKeys.setNewTrip(),
    mutationFn: async (data) => {
      const response = await tripsApi.setNewTrip(data);
      return response.data;
    }
  });
};
