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

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

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

export const useGetCountryDataQuery = (id: number, enabled: boolean, token?: string) => {
  return useQuery<PostGetCountryDataReturn, BaseAxiosError>({
    queryKey: countriesQueryKeys.getCountryData(id, token),
    queryFn: async () => {
      const response = await countriesApi.getCountryData(id, token);
      return response.data;
    },
    enabled
  });
};
