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

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

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

export const fetchCountryUserData = () => {
  return useMutation<
    PostGetUserDataReturn,
    BaseAxiosError,
    { token: string; id: number },
    PostGetUserDataReturn
  >({
    mutationKey: countriesQueryKeys.getCountryUserData(),
    mutationFn: async (variables) => {
      const response = await countriesApi.getCountryUserData(variables.id, variables.token);
      return response.data;
    }
  });
};
