import axios from 'axios';
import { API_URL_ADDITIONAL_SERVICE } from '@/shared/api/api-url-additional-service';
import { resultify } from '@/shared/lib/resultify';
import { NiceAxiosError } from '@/shared/@types/error';
import {
  ExtensionSmsResendParams,
  ExtensionSmsResendResponse
} from '../../model/sms-payment/types';
import {
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';
import { getHeaderUserAgent } from '@/shared/constants/url';

export const extensionSmsResend = (params: ExtensionSmsResendParams) => {
  let headerOptions = {
    menuId: 57,
    apiType: 'UPDATE'
  };
  let options = {
    headers: {
      'X-User-Agent': getHeaderUserAgent(headerOptions)
    }
  };
  return resultify(
    axios.post<ExtensionSmsResendResponse>(API_URL_ADDITIONAL_SERVICE.extensionSmsResend(), params, options),
  );
};

export const useExtensionSmsResendMutation = (options?: UseMutationOptions<ExtensionSmsResendResponse, NiceAxiosError, ExtensionSmsResendParams>) => {
  const mutation = useMutation<ExtensionSmsResendResponse, NiceAxiosError, ExtensionSmsResendParams>({
    ...options,
    mutationFn: (params: ExtensionSmsResendParams) => extensionSmsResend(params),
  });

  return {
    ...mutation,
  };
};
