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 { ExtensionKeyinDownloadExcelParams, ExtensionKeyinDownloadExcelResponse } from '../model/key-in/types';
import { getHeaderUserAgent } from '@/shared/constants/url';

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

export const useExtensionKeyinDownloadExcelMutation = (options?: UseMutationOptions<ExtensionKeyinDownloadExcelResponse, NiceAxiosError, ExtensionKeyinDownloadExcelParams>) => {
  const mutation = useMutation<ExtensionKeyinDownloadExcelResponse, NiceAxiosError, ExtensionKeyinDownloadExcelParams>({
    ...options,
    mutationFn: (params: ExtensionKeyinDownloadExcelParams) => extensionKeyinDownloadExcel(params),
  });

  return {
    ...mutation,
  };
};
