import axios from 'axios';
import { API_URL } from '@/shared/api/urls';
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.allTransactionCancel(), params),
  );
};

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

  return {
    ...mutation,
  };
};
