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

export const emptyTokenVerifyCode = (params: EmptyTokenVerifyCodeParams) => {
  return resultify(
    axios.post<EmptyTokenVerifyCodeResponse>(API_URL.emptyTokenVerifyCode(), params),
  );
};

export const useEmptyTokenVerifyCodeMutation = (options?: UseMutationOptions<EmptyTokenVerifyCodeResponse, NiceAxiosError, EmptyTokenVerifyCodeParams>) => {
  const mutation = useMutation<EmptyTokenVerifyCodeResponse, NiceAxiosError, EmptyTokenVerifyCodeParams>({
    ...options,
    mutationFn: (params: EmptyTokenVerifyCodeParams) => emptyTokenVerifyCode(params),
  });

  return {
    ...mutation,
  };
};
