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

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

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

export const useGetTripsYearsQuery = (token: string, enabled: boolean) => {
  return useQuery<PostGetTripsYearsReturn, BaseAxiosError>({
    queryKey: tripsQueryKeys.getTripsYears(token),
    queryFn: async () => {
      const response = await tripsApi.getTripsYears(token);
      return response.data;
    },
    enabled
  });
};
