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

export const escrowMailResend = (params: EscrowMailResendParams) => {
  return resultify(
    axios.post<EscrowMailResendResponse>(API_URL.escrowMailResend(), params),
  );
};

export const useEscrowMailResendMutation = (options?: UseMutationOptions<EscrowMailResendResponse, CBDCAxiosError, EscrowMailResendParams>) => {
  const mutation = useMutation<EscrowMailResendResponse, CBDCAxiosError, EscrowMailResendParams>({
    ...options,
    mutationFn: (params: EscrowMailResendParams) => escrowMailResend(params),
  });

  return {
    ...mutation,
  };
};
