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 { ExtensionAccountHolderSearchDownloadExcelParams, ExtensionAccountHolderSearchDownloadExcelResponse } from '../../model/account-holder-search/types';
import { getHeaderUserAgent } from '@/shared/constants/url';

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

export const useExtensionAccountHolderSearchDownloadExcelMutation = (options?: UseMutationOptions<ExtensionAccountHolderSearchDownloadExcelResponse, NiceAxiosError, ExtensionAccountHolderSearchDownloadExcelParams>) => {
  const mutation = useMutation<ExtensionAccountHolderSearchDownloadExcelResponse, NiceAxiosError, ExtensionAccountHolderSearchDownloadExcelParams>({
    ...options,
    mutationFn: (params: ExtensionAccountHolderSearchDownloadExcelParams) => extensionAccountHolderSearchDownloadExcel(params),
  });

  return {
    ...mutation,
  };
};
