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

import { tripsQueryKeys } from '../trips-query-keys';
import { type PostUpdateTrip, tripsApi } from '../trips-api';
import { ResponseType } from '../../response-type';

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

export const usePostUpdateTripMutation = () => {
  return useMutation<ResponseType, BaseAxiosError, PostUpdateTrip, ResponseType>({
    mutationKey: tripsQueryKeys.updateTrip(),
    mutationFn: async (data) => {
      const response = await tripsApi.updateTrip(data);
      return response.data;
    }
  });
};
