import axios from 'axios';
import { API_URL_TRANSACTION } from '@/shared/api/api-url-transaction';
import { resultify } from '@/shared/lib/resultify';
import { CBDCAxiosError } from '@/shared/@types/error';
import { 
  DownloadConfirmationParams,
  DownloadConfirmationResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const downloadConfirmation = (params: DownloadConfirmationParams) => {
  return resultify(
    axios.post<DownloadConfirmationResponse>(API_URL_TRANSACTION.downloadConfirmation(), params),
  );
};

export const useDownloadConfirmationMutation = (options?: UseMutationOptions<DownloadConfirmationResponse, CBDCAxiosError, DownloadConfirmationParams>) => {
  const mutation = useMutation<DownloadConfirmationResponse, CBDCAxiosError, DownloadConfirmationParams>({
    ...options,
    mutationFn: (params: DownloadConfirmationParams) => downloadConfirmation(params),
  });

  return {
    ...mutation,
  };
};
