/*
   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_reserve_open_above_serial_id.h
 * @brief implementation of the select_reserve_open_above_serial_id function
 * @author Christian Grothoff
 */
#ifndef EXCHANGE_DATABASE_ITERATE_RESERVE_OPEN_ABOVE_SERIAL_ID_H
#define EXCHANGE_DATABASE_ITERATE_RESERVE_OPEN_ABOVE_SERIAL_ID_H

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


/**
 * Function called about reserve opening operations.
 *
 * @param cls closure
 * @param rowid row identifier used to uniquely identify the reserve closing operation
 * @param reserve_payment how much to pay from the
 *        reserve's own balance for opening the reserve
 * @param request_timestamp when was the request created
 * @param reserve_expiration desired expiration time for the reserve
 * @param purse_limit minimum number of purses the client
 *       wants to have concurrently open for this reserve
 * @param reserve_pub public key of the reserve
 * @param reserve_sig signature affirming the operation
 * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
 */
#ifndef TALER_EXCHANGEDB_RESERVE_OPEN_RESULT_CLOSURE
/**
 * Type of the closure for #TALER_EXCHANGEDB_ReserveOpenCallback.
 */
#define TALER_EXCHANGEDB_RESERVE_OPEN_RESULT_CLOSURE void
#endif
typedef enum GNUNET_GenericReturnValue
(*TALER_EXCHANGEDB_ReserveOpenCallback)(
  TALER_EXCHANGEDB_RESERVE_OPEN_RESULT_CLOSURE *cls,
  uint64_t rowid,
  const struct TALER_Amount *reserve_payment,
  struct GNUNET_TIME_Timestamp request_timestamp,
  struct GNUNET_TIME_Timestamp reserve_expiration,
  uint32_t purse_limit,
  const struct TALER_ReservePublicKeyP *reserve_pub,
  const struct TALER_ReserveSignatureP *reserve_sig);


/* Callback typedefs */
/**
 * Function called about reserve opening operations.
 *
 * @param cls closure
 * @param rowid row identifier used to uniquely identify the reserve closing operation
 * @param reserve_payment how much to pay from the
 *        reserve's own balance for opening the reserve
 * @param request_timestamp when was the request created
 * @param reserve_expiration desired expiration time for the reserve
 * @param purse_limit minimum number of purses the client
 *       wants to have concurrently open for this reserve
 * @param reserve_pub public key of the reserve
 * @param reserve_sig signature affirming the operation
 * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
 */
typedef enum GNUNET_GenericReturnValue
(*TALER_EXCHANGEDB_ReserveOpenCallback)(
  TALER_EXCHANGEDB_RESERVE_OPEN_RESULT_CLOSURE *cls,
  uint64_t rowid,
  const struct TALER_Amount *reserve_payment,
  struct GNUNET_TIME_Timestamp request_timestamp,
  struct GNUNET_TIME_Timestamp reserve_expiration,
  uint32_t purse_limit,
  const struct TALER_ReservePublicKeyP *reserve_pub,
  const struct TALER_ReserveSignatureP *reserve_sig);

/**
 * Function called to select reserve open operations, ordered by serial ID
 * (monotonically increasing).
 *
 * @param pg the database context
 * @param serial_id lowest serial ID to include (select larger or equal)
 * @param cb function to call for ONE unfinished item
 * @param cb_cls closure for @a cb
 * @return transaction status code
 */
enum GNUNET_DB_QueryStatus
TALER_EXCHANGEDB_iterate_reserve_open_above_serial_id (struct
                                                       TALER_EXCHANGEDB_PostgresContext
                                                       *pg,
                                                       uint64_t serial_id,
                                                       TALER_EXCHANGEDB_ReserveOpenCallback
                                                       cb,
                                                       TALER_EXCHANGEDB_RESERVE_OPEN_RESULT_CLOSURE
                                                       *cb_cls);


#endif
