/*
   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 src/include/exchange-database/iterate_global_fees.h
 * @brief implementation of the iterate_global_fees function for Postgres
 * @author Christian Grothoff
 */
#ifndef EXCHANGE_DATABASE_ITERATE_GLOBAL_FEES_H
#define EXCHANGE_DATABASE_ITERATE_GLOBAL_FEES_H

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


/**
 * Provide information about global fees.
 *
 * @param cls closure
 * @param fees the global fees we charge
 * @param purse_timeout when do purses time out
 * @param history_expiration how long are account histories preserved
 * @param purse_account_limit how many purses are free per account
 * @param start_date from when are these fees valid (start date)
 * @param end_date until when are these fees valid (end date, exclusive)
 * @param master_sig master key signature affirming that this is the correct
 *                   fee (of purpose #TALER_SIGNATURE_MASTER_GLOBAL_FEES)
 */
#ifndef TALER_EXCHANGEDB_GLOBAL_FEE_RESULT_CLOSURE
/**
 * Type of the closure for #TALER_EXCHANGEDB_GlobalFeeCallback.
 */
#define TALER_EXCHANGEDB_GLOBAL_FEE_RESULT_CLOSURE void
#endif
typedef void
(*TALER_EXCHANGEDB_GlobalFeeCallback)(
  TALER_EXCHANGEDB_GLOBAL_FEE_RESULT_CLOSURE *cls,
  const struct TALER_GlobalFeeSet *fees,
  struct GNUNET_TIME_Relative purse_timeout,
  struct GNUNET_TIME_Relative history_expiration,
  uint32_t purse_account_limit,
  struct GNUNET_TIME_Timestamp start_date,
  struct GNUNET_TIME_Timestamp end_date,
  const struct TALER_MasterSignatureP *master_sig);


/* Callback typedefs */
/**
 * Provide information about global fees.
 *
 * @param cls closure
 * @param fees the global fees we charge
 * @param purse_timeout when do purses time out
 * @param history_expiration how long are account histories preserved
 * @param purse_account_limit how many purses are free per account
 * @param start_date from when are these fees valid (start date)
 * @param end_date until when are these fees valid (end date, exclusive)
 * @param master_sig master key signature affirming that this is the correct
 *                   fee (of purpose #TALER_SIGNATURE_MASTER_GLOBAL_FEES)
 */
typedef void
(*TALER_EXCHANGEDB_GlobalFeeCallback)(
  TALER_EXCHANGEDB_GLOBAL_FEE_RESULT_CLOSURE *cls,
  const struct TALER_GlobalFeeSet *fees,
  struct GNUNET_TIME_Relative purse_timeout,
  struct GNUNET_TIME_Relative history_expiration,
  uint32_t purse_account_limit,
  struct GNUNET_TIME_Timestamp start_date,
  struct GNUNET_TIME_Timestamp end_date,
  const struct TALER_MasterSignatureP *master_sig);

/**
 * Obtain global fees from database.
 *
 * @param pg the database context
 * @param cb function to call on each fee entry
 * @param cb_cls closure for @a cb
 * @return status of the transaction
 */
enum GNUNET_DB_QueryStatus
TALER_EXCHANGEDB_iterate_global_fees (struct
                                      TALER_EXCHANGEDB_PostgresContext *pg,
                                      TALER_EXCHANGEDB_GlobalFeeCallback cb,
                                      TALER_EXCHANGEDB_GLOBAL_FEE_RESULT_CLOSURE
                                      *cb_cls);

#endif
