import axios from 'axios';
import { API_URL_TRANSACTION } from '@/shared/api/api-url-transaction';
import { resultify } from '@/shared/lib/resultify';
import { NiceAxiosError } from '@/shared/@types/error';
import { 
  EscrowMailResendParams,
  EscrowMailResendResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';
import { getHeaderUserAgent } from '@/shared/constants/url';

export const escrowMailResend = (params: EscrowMailResendParams) => {
  let headerOptions = {
    menuId: 33,
    apiType: 'MAIL'
  };
  let options = {
    headers: {
      'X-User-Agent': getHeaderUserAgent(headerOptions)
    }
  };
  return resultify(
    axios.post<EscrowMailResendResponse>(API_URL_TRANSACTION.escrowMailResend(), params, options),
  );
};

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

  return {
    ...mutation,
  };
};
