import axios from 'axios';
import { API_URL } from '@/shared/api/urls';
import { resultify } from '@/shared/lib/resultify';
import { CBDCAxiosError } from '@/shared/@types/error';
import { 
  DownloadExcelParams,
  DownloadExcelResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const downloadExcel = (params: DownloadExcelParams) => {
  return resultify(
    axios.post<DownloadExcelResponse>(API_URL.downloadExcel(), params),
  );
};

export const useDownloadExcelMutation = (options?: UseMutationOptions<DownloadExcelResponse, CBDCAxiosError, DownloadExcelParams>) => {
  const mutation = useMutation<DownloadExcelResponse, CBDCAxiosError, DownloadExcelParams>({
    ...options,
    mutationFn: (params: DownloadExcelParams) => downloadExcel(params),
  });

  return {
    ...mutation,
  };
};
