import axios from 'axios';
import { API_URL_ADDITIONAL_SERVICE } from '@/shared/api/api-url-additional-service';
import { resultify } from '@/shared/lib/resultify';
import { CBDCAxiosError } from '@/shared/@types/error';
import { 
  ExtensionLinkPayHistoryDownloadExcelRespone,
  ExtensionLinkPayHistoryDownloadExcelParams
} from '../../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const extensionLinkPayHistoryDownloadExcel = (params: ExtensionLinkPayHistoryDownloadExcelParams) => {
  return resultify(
    axios.post<ExtensionLinkPayHistoryDownloadExcelRespone>(API_URL_ADDITIONAL_SERVICE.extensionLinkPaymentHistoryDownloadExcel(), params),
  );
};

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

  return {
    ...mutation,
  };
};