/*
   This file is part of TALER
   Copyright (C) 2023 Taler Systems SA

   TALER is free software; you can redistribute it and/or modify it under the
   terms of the GNU General Public License as published by the Free Software
   Foundation; either version 3, or (at your option) any later version.

   TALER is distributed in the hope that it will be useful, but WITHOUT ANY
   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
   A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

   You should have received a copy of the GNU General Public License along with
   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
 */
/**
 * @file src/include/exchange-database/iterate_aggregations_above_serial_id.h
 * @brief implementation of the iterate_aggregations_above_serial_id function for Postgres
 * @author Christian Grothoff
 */
#ifndef EXCHANGE_DATABASE_ITERATE_AGGREGATIONS_ABOVE_SERIAL_ID_H
#define EXCHANGE_DATABASE_ITERATE_AGGREGATIONS_ABOVE_SERIAL_ID_H

#include "taler/taler_util.h"
#include "taler/taler_json_lib.h"
#include "exchangedb_lib.h"


/**
 * Function called on aggregations that were done for
 * a (batch) deposit.
 *
 * @param cls closure
 * @param amount affected amount
 * @param tracking_serial_id where in the table are we
 * @param batch_deposit_serial_id which batch deposit was aggregated
 */
#ifndef TALER_EXCHANGEDB_AGGREGATION_RESULT_CLOSURE
/**
 * Type of the closure for #TALER_EXCHANGEDB_AggregationCallback.
 */
#define TALER_EXCHANGEDB_AGGREGATION_RESULT_CLOSURE void
#endif
typedef void
(*TALER_EXCHANGEDB_AggregationCallback)(
  TALER_EXCHANGEDB_AGGREGATION_RESULT_CLOSURE *cls,
  const struct TALER_Amount *amount,
  uint64_t tracking_serial_id,
  uint64_t batch_deposit_serial_id);


/* Callback typedefs */
/**
 * Function called on aggregations that were done for
 * a (batch) deposit.
 *
 * @param cls closure
 * @param amount affected amount
 * @param tracking_serial_id where in the table are we
 * @param batch_deposit_serial_id which batch deposit was aggregated
 */
typedef void
(*TALER_EXCHANGEDB_AggregationCallback)(
  TALER_EXCHANGEDB_AGGREGATION_RESULT_CLOSURE *cls,
  const struct TALER_Amount *amount,
  uint64_t tracking_serial_id,
  uint64_t batch_deposit_serial_id);

/**
 * Select all aggregation tracking IDs in the database
 * above a given @a min_tracking_serial_id.
 *
 * @param pg the database context
 * @param min_tracking_serial_id only return entries strictly above this row (and in order)
 * @param cb function to call on all such aggregations
 * @param cb_cls closure for @a cb
 * @return transaction status code
 */
enum GNUNET_DB_QueryStatus
TALER_EXCHANGEDB_iterate_aggregations_above_serial_id (struct
                                                       TALER_EXCHANGEDB_PostgresContext
                                                       *
                                                       pg,
                                                       uint64_t
                                                       min_tracking_serial_id,
                                                       TALER_EXCHANGEDB_AggregationCallback
                                                       cb,
                                                       TALER_EXCHANGEDB_AGGREGATION_RESULT_CLOSURE
                                                       *cb_cls);


#endif
