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

export const allTransactionListSummary = (params: AllTransactionListSummaryParams) => {
  return resultify(
    axios.post<AllTransactionListSummaryResponse>(API_URL_TRANSACTION.allTransactionListSummary(), params),
  );
};

export const useAllTransactionListSummaryMutation = (options?: UseMutationOptions<AllTransactionListSummaryResponse, CBDCAxiosError, AllTransactionListSummaryParams>) => {
  const mutation = useMutation<AllTransactionListSummaryResponse, CBDCAxiosError, AllTransactionListSummaryParams>({
    ...options,
    mutationFn: (params: AllTransactionListSummaryParams) => allTransactionListSummary(params),
  });

  return {
    ...mutation,
  };
};
