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 {
  ExtensionFundAccountResultExcelParams,
  ExtensionFundAccountResultExcelResponse
} from '../../model/fund-account/types';
import {
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';
import { getHeaderUserAgent } from '@/shared/constants/url';

export const extensionFundAccountResultExcel = (params: ExtensionFundAccountResultExcelParams) => {
  let headerOptions = {
    menuId: 55,
    apiType: 'SELECT'
  };
  let options = {
    headers: {
      'X-User-Agent': getHeaderUserAgent(headerOptions)
    }
  };
  return resultify(
    axios.post<ExtensionFundAccountResultExcelResponse>(API_URL_ADDITIONAL_SERVICE.extensionFundAccountResultExcel(), params, options),
  );
};

export const useExtensionFundAccountResultExcelMutation = (options?: UseMutationOptions<ExtensionFundAccountResultExcelResponse, NiceAxiosError, ExtensionFundAccountResultExcelParams>) => {
  const mutation = useMutation<ExtensionFundAccountResultExcelResponse, NiceAxiosError, ExtensionFundAccountResultExcelParams>({
    ...options,
    mutationFn: (params: ExtensionFundAccountResultExcelParams) => extensionFundAccountResultExcel(params),
  });

  return {
    ...mutation,
  };
};
