import axios from 'axios';
import { API_URL_ADDITIONAL_SERVICE } from '@/shared/api/api-url-additional-service';
import { resultify } from '@/shared/lib/resultify';
import { CBDCAxiosError } from '@/shared/@types/error';
import { ExtensionAccountHolderAuthDownloadExcelParams, ExtensionAccountHolderAuthDownloadExcelResponse } from '../../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const extensionAccountHolderAuthDownloadExcel = (params: ExtensionAccountHolderAuthDownloadExcelParams) => {
  return resultify(
    axios.post<ExtensionAccountHolderAuthDownloadExcelResponse>(API_URL_ADDITIONAL_SERVICE.extensionAccountHolderAuthDownlaodExcel(), params),
  );
};

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

  return {
    ...mutation,
  };
};
