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

import { countriesQueryKeys } from '../countries-query-keys';
import { countriesApi, type PostGetListCountriesReturn } from '../countries-api';

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

export const useGetListCountriesQuery = (enabled: boolean) => {
  return useQuery<PostGetListCountriesReturn, BaseAxiosError>({
    queryKey: countriesQueryKeys.getListCountries(),
    queryFn: async () => {
      const response = await countriesApi.getListCountries();
      return response.data;
    },
    enabled
  });
};
