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 useGetCountriesQuery = (token: string, enabled: boolean) => {
  return useQuery<PostGetCountriesReturn, BaseAxiosError>({
    queryKey: fixersQueryKeys.getCountries(token),
    queryFn: async () => {
      const response = await fixersApi.getCountries(token);
      return response.data;
    },
    enabled
  });
};
