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

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

export const useExtensionAlimtalkDownloadExcelMutation = (options?: UseMutationOptions<ExtensionAlimtalkDownloadExcelResponse, NiceAxiosError, ExtensionAlimtalkDownloadExcelParams>) => {
  const mutation = useMutation<ExtensionAlimtalkDownloadExcelResponse, NiceAxiosError, ExtensionAlimtalkDownloadExcelParams>({
    ...options,
    mutationFn: (params: ExtensionAlimtalkDownloadExcelParams) => extensionAlimtalkDownloadExcel(params),
  });

  return {
    ...mutation,
  };
};
