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

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

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

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