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

import { userQueryKeys } from '../user-query-keys';
import { type PostGetMapYearsReturn, userApi } from '../user-api';

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

export const usePostGetMapYearsQuery = (token: string, userId: number, enabled: boolean) => {
  return useQuery<PostGetMapYearsReturn, BaseAxiosError>({
    queryKey: userQueryKeys.getMapYears(userId),
    queryFn: async () => {
      const response = await userApi.getMapYears(token, userId);
      return response.data;
    },
    enabled
  });
};
