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 {
    useMutation,
    UseMutationOptions
} from '@tanstack/react-query';
import { ExtensionLinkPayRequestParams, ExtensionLinkPayRequestResponse } from '../../model/link-pay/types';
import { getHeaderUserAgent } from '@/shared/constants/url';

export const extensionLinkPayRequest = (params: ExtensionLinkPayRequestParams) => {
  let headerOptions = {
    menuId: 54,
    apiType: 'INSERT'
  };
  let options = {
    headers: {
      'X-User-Agent': getHeaderUserAgent(headerOptions)
    }
  };
  return resultify(
    axios.post<ExtensionLinkPayRequestResponse>(API_URL_ADDITIONAL_SERVICE.extensionLinkPaymentRequest(), params, options),
  );
};

export const useExtensionLinkPayRequestMutation = (options?: UseMutationOptions<ExtensionLinkPayRequestResponse, NiceAxiosError, ExtensionLinkPayRequestParams>) => {
  const mutation = useMutation<ExtensionLinkPayRequestResponse, NiceAxiosError, ExtensionLinkPayRequestParams>({
    ...options,
    mutationFn: (params: ExtensionLinkPayRequestParams) => extensionLinkPayRequest(params),
  });

  return {
    ...mutation,
  };
};