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

export const extensionAccountHolderAuthDownloadExcel = (params: ExtensionAccountHolderAuthDownloadExcelParams) => {
  let headerOptions = {
    menuId: 59,
    apiType: 'SELECT'
  };
  let options = {
    headers: {
      'X-User-Agent': getHeaderUserAgent(headerOptions)
    }
  }
  return resultify(
    axios.post<ExtensionAccountHolderAuthDownloadExcelResponse>(API_URL_ADDITIONAL_SERVICE.extensionAccountHolderAuthDownlaodExcel(), params, options),
  );
};

export const useExtensionAccountHolderAuthDownloadExcelMutation = (options?: UseMutationOptions<ExtensionAccountHolderAuthDownloadExcelResponse, NiceAxiosError, ExtensionAccountHolderAuthDownloadExcelParams>) => {
  const mutation = useMutation<ExtensionAccountHolderAuthDownloadExcelResponse, NiceAxiosError, ExtensionAccountHolderAuthDownloadExcelParams>({
    ...options,
    mutationFn: (params: ExtensionAccountHolderAuthDownloadExcelParams) => extensionAccountHolderAuthDownloadExcel(params),
  });

  return {
    ...mutation,
  };
};
