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

export const emptyTokenFindSendCode = (params: EmptyTokenFindSendCodeParams) => {
  return resultify(
    axios.post<EmptyTokenFindSendCodeResponse>(API_URL.emptyTokenFindSendCode(), params),
  );
};

export const useEmptyTokenFindSendCodeMutation = (options?: UseMutationOptions<EmptyTokenFindSendCodeResponse, NiceAxiosError, EmptyTokenFindSendCodeParams>) => {
  const mutation = useMutation<EmptyTokenFindSendCodeResponse, NiceAxiosError, EmptyTokenFindSendCodeParams>({
    ...options,
    mutationFn: (params: EmptyTokenFindSendCodeParams) => emptyTokenFindSendCode(params),
  });

  return {
    ...mutation,
  };
};
