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

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

export const useExtensionSmsDownloadExcelMutation = (options?: UseMutationOptions<ExtensionSmsDownloadExcelResponse, NiceAxiosError, ExtensionSmsDownloadExcelParams>) => {
  const mutation = useMutation<ExtensionSmsDownloadExcelResponse, NiceAxiosError, ExtensionSmsDownloadExcelParams>({
    ...options,
    mutationFn: (params: ExtensionSmsDownloadExcelParams) => extensionSmsDownloadExcel(params),
  });

  return {
    ...mutation,
  };
};
