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

export const allTransactionDetail = (params: AllTransactionDetailParams) => {
  return resultify(
    axios.post<DetailResponse>(API_URL_TRANSACTION.allTransactionDetail(), params),
  );
};

export const useAllTransactionDetailMutation = (options?: UseMutationOptions<DetailResponse, CBDCAxiosError, AllTransactionDetailParams>) => {
  const mutation = useMutation<DetailResponse, CBDCAxiosError, AllTransactionDetailParams>({
    ...options,
    mutationFn: (params: AllTransactionDetailParams) => allTransactionDetail(params),
  });

  return {
    ...mutation,
  };
};
