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

import { mapsQueryKeys } from '../maps-query-keys';
import { mapsApi, type PostGetVisitedIds } from '../maps-api';

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

export const usePostGetVisitedCountriesIdsQuery = (
  token: string,
  type: 'in' | 'by',
  year: number,
  uid: number,
  enabled: boolean,
  forceRefetch: number = 0
) => {
  return useQuery<PostGetVisitedIds, BaseAxiosError>({
    queryKey: [...mapsQueryKeys.getVisitedCountriesIds(token, type, year, uid), forceRefetch],
    queryFn: async () => {
      const response = await mapsApi.getVisitedCountriesIds(token, type, year, uid);
      return response.data;
    },
    enabled,
    staleTime: 0,
    gcTime: 0,
  });
};
