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

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

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

export const usePostDeleteTripMutation = () => {
  return useMutation<
    ResponseType,
    BaseAxiosError,
    { token: string; trip_id: number },
    ResponseType
  >({
    mutationKey: tripsQueryKeys.deleteTrip(),
    mutationFn: async (variables) => {
      const response = await tripsApi.deleteTrip(variables.token, variables.trip_id);
      return response.data;
    }
  });
};
