import axios from 'axios';
import { API_URL } from '@/shared/api/urls';
import { resultify } from '@/shared/lib/resultify';
import { NiceAxiosError } from '@/shared/@types/error';
import { 
  EmptyTokenChangeParams,
  EmptyTokenChangeResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const emptyTokenChange = (params: EmptyTokenChangeParams) => {
  return resultify(
    axios.post<EmptyTokenChangeResponse>(API_URL.emptyTokenChange(), params),
  );
};

export const useEmptyTokenChangeMutation = (options?: UseMutationOptions<EmptyTokenChangeResponse, NiceAxiosError, EmptyTokenChangeParams>) => {
  const mutation = useMutation<EmptyTokenChangeResponse, NiceAxiosError, EmptyTokenChangeParams>({
    ...options,
    mutationFn: (params: EmptyTokenChangeParams) => emptyTokenChange(params),
  });

  return {
    ...mutation,
  };
};
