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

import { locationQueryKeys } from '../location-query-keys';
import { locationApi, type PostGetCountriesReturn } from '../location-api';

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

export const usePostGetListOfCountriesForLocationDataQuery = (token: string, enabled: boolean) => {
  return useQuery<PostGetCountriesReturn, BaseAxiosError>({
    queryKey: locationQueryKeys.getCountries(token),
    queryFn: async () => {
      const response = await locationApi.getCountries(token);
      return response.data;
    },
    enabled
  });
};
