/*
   This file is part of TALER
   Copyright (C) 2022 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 iterate_historic_reserve_revenue.h
 * @brief implementation of the select_historic_reserve_revenue function
 * @author Christian Grothoff
 */
#ifndef AUDITOR_DATABASE_ITERATE_HISTORIC_RESERVE_REVENUE_H
#define AUDITOR_DATABASE_ITERATE_HISTORIC_RESERVE_REVENUE_H

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


/**
 * Function called with the results of select_historic_reserve_revenue()
 *
 * @param cls closure
 * @param serial_id row ID in the history table
 * @param start_time beginning of aggregated time interval
 * @param end_time end of aggregated time interval
 * @param reserve_profits total profits made
 *
 * @return sets the return value of select_denomination_info(),
 *         #GNUNET_OK to continue,
 *         #GNUNET_NO to stop processing further rows
 *         #GNUNET_SYSERR or other values on error.
 */
#ifndef TALER_AUDITORDB_HISTORIC_RESERVE_REVENUE_DATA_RESULT_CLOSURE
/**
 * Type of the closure for #TALER_AUDITORDB_HistoricReserveRevenueDataCallback.
 */
#define TALER_AUDITORDB_HISTORIC_RESERVE_REVENUE_DATA_RESULT_CLOSURE void
#endif
typedef enum GNUNET_GenericReturnValue
(*TALER_AUDITORDB_HistoricReserveRevenueDataCallback)(
  TALER_AUDITORDB_HISTORIC_RESERVE_REVENUE_DATA_RESULT_CLOSURE *cls,
  uint64_t serial_id,
  struct GNUNET_TIME_Timestamp start_time,
  struct GNUNET_TIME_Timestamp end_time,
  const struct TALER_Amount *reserve_profits);


/* Callback typedefs */
/**
 * Function called with the results of select_historic_reserve_revenue()
 *
 * @param cls closure
 * @param serial_id row ID in the history table
 * @param start_time beginning of aggregated time interval
 * @param end_time end of aggregated time interval
 * @param reserve_profits total profits made
 *
 * @return sets the return value of select_denomination_info(),
 *         #GNUNET_OK to continue,
 *         #GNUNET_NO to stop processing further rows
 *         #GNUNET_SYSERR or other values on error.
 */
typedef enum GNUNET_GenericReturnValue
(*TALER_AUDITORDB_HistoricReserveRevenueDataCallback)(
  TALER_AUDITORDB_HISTORIC_RESERVE_REVENUE_DATA_RESULT_CLOSURE *cls,
  uint64_t serial_id,
  struct GNUNET_TIME_Timestamp start_time,
  struct GNUNET_TIME_Timestamp end_time,
  const struct TALER_Amount *reserve_profits);

/**
 * Return information about an exchange's historic revenue from reserves.
 *
 * @param pg the database context
 * @param limit return at most this number of results, negative to descend from @a offset
 * @param offset row from which to return @a limit results
 * @param cb function to call with results
 * @param cb_cls closure for @a cb
 * @return transaction status code
 */
enum GNUNET_DB_QueryStatus
TALER_AUDITORDB_iterate_historic_reserve_revenue (struct
                                                  TALER_AUDITORDB_PostgresContext
                                                  *pg,
                                                  int64_t limit,
                                                  uint64_t offset,
                                                  TALER_AUDITORDB_HistoricReserveRevenueDataCallback
                                                  cb,
                                                  TALER_AUDITORDB_HISTORIC_RESERVE_REVENUE_DATA_RESULT_CLOSURE
                                                  *cb_cls);


#endif
