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

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

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

export const useGetTripQuery = (token: string, trip_id: number, enabled: boolean) => {
  return useQuery<PostGetTripReturn, BaseAxiosError>({
    queryKey: tripsQueryKeys.getTrip(token, trip_id),
    queryFn: async () => {
      const response = await tripsApi.getTrip(token, trip_id);
      return response.data;
    },
    enabled
  });
};
