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 { 
  ExtensionKeyinDownloadExcelParams,
  ExtensionKeyinDownloadExcelResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const extensionKeyinDownloadExcel = (params: ExtensionKeyinDownloadExcelParams) => {
  return resultify(
    axios.post<ExtensionKeyinDownloadExcelResponse>(API_URL_ADDITIONAL_SERVICE.extensionKeyinDownloadExcel(), params),
  );
};

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

  return {
    ...mutation,
  };
};
