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

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

  return {
    ...mutation,
  };
};
