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

import { fixersQueryKeys } from '../fixers-query-keys';
import { fixersApi, type PostGetCountriesReturn } from '../fixers-api';

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

export const useGetAllCountriesQuery = (token: string, enabled: boolean) => {
  return useQuery<PostGetCountriesReturn, BaseAxiosError>({
    queryKey: fixersQueryKeys.getAllCountries(token),
    queryFn: async () => {
      const response = await fixersApi.getAllCountries(token);
      return response.data;
    },
    enabled
  });
};
