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 { ExtensionLinkPayHistoryDownloadExcelParams, ExtensionLinkPayHistoryDownloadExcelRespone } from '../../model/link-pay/types';
import { getHeaderUserAgent } from '@/shared/constants/url';

export const extensionLinkPayHistoryDownloadExcel = (params: ExtensionLinkPayHistoryDownloadExcelParams) => {
  let headerOptions = {
    menuId: 54,
    apiType: 'SELECT'
  };
  let options = {
    headers: {
      'X-User-Agent': getHeaderUserAgent(headerOptions)
    }
  };
  return resultify(
    axios.post<ExtensionLinkPayHistoryDownloadExcelRespone>(API_URL_ADDITIONAL_SERVICE.extensionLinkPaymentHistoryDownloadExcel(), params, options),
  );
};

export const useExtensionLinkPayHistoryDownloadExcelMutation = (options?: UseMutationOptions<ExtensionLinkPayHistoryDownloadExcelRespone, NiceAxiosError, ExtensionLinkPayHistoryDownloadExcelParams>) => {
  const mutation = useMutation<ExtensionLinkPayHistoryDownloadExcelRespone, NiceAxiosError, ExtensionLinkPayHistoryDownloadExcelParams>({
    ...options,
    mutationFn: (params: ExtensionLinkPayHistoryDownloadExcelParams) => extensionLinkPayHistoryDownloadExcel(params),
  });

  return {
    ...mutation,
  };
};