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

export const allTransactionCancel = (params: AllTransactionCancelParams) => {
  return resultify(
    axios.post<AllTransactionCancelResponse>(API_URL_TRANSACTION.allTransactionCancel(), params),
  );
};

export const useAllTransactioCancleMutation = (options?: UseMutationOptions<AllTransactionCancelResponse, CBDCAxiosError, AllTransactionCancelParams>) => {
  const mutation = useMutation<AllTransactionCancelResponse, CBDCAxiosError, AllTransactionCancelParams>({
    ...options,
    mutationFn: (params: AllTransactionCancelParams) => allTransactionCancel(params),
  });

  return {
    ...mutation,
  };
};
