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

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


/* Callback typedefs */
/**
 * Function called with details about expired reserves.
 *
 * @param cls closure
 * @param reserve_pub public key of the reserve
 * @param left amount left in the reserve
 * @param account_details information about the reserve's bank account, in payto://-format
 * @param expiration_date when did the reserve expire
 * @param close_request_row row that caused the reserve
 *        to be closed, 0 if it expired without request
 * @return #GNUNET_OK on success,
 *         #GNUNET_NO to retry
 *         #GNUNET_SYSERR on hard failures (exit)
 */
#ifndef TALER_EXCHANGEDB_RESERVE_EXPIRED_RESULT_CLOSURE
/**
 * Type of the closure for #TALER_EXCHANGEDB_ReserveExpiredCallback.
 */
#define TALER_EXCHANGEDB_RESERVE_EXPIRED_RESULT_CLOSURE void
#endif
typedef enum GNUNET_GenericReturnValue
(*TALER_EXCHANGEDB_ReserveExpiredCallback)(
  TALER_EXCHANGEDB_RESERVE_EXPIRED_RESULT_CLOSURE *cls,
  const struct TALER_ReservePublicKeyP *reserve_pub,
  const struct TALER_Amount *left,
  const struct TALER_FullPayto account_details,
  struct GNUNET_TIME_Timestamp expiration_date,
  uint64_t close_request_row);

/**
 * Obtain information about expired reserves and their
 * remaining balances.
 *
 * @param pg the database context
 * @param now timestamp based on which we decide expiration
 * @param rec function to call on expired reserves
 * @param rec_cls closure for @a rec
 * @return transaction status
 */
enum GNUNET_DB_QueryStatus
TALER_EXCHANGEDB_iterate_expired_reserves (struct
                                           TALER_EXCHANGEDB_PostgresContext *
                                           pg,
                                           struct GNUNET_TIME_Timestamp now,
                                           TALER_EXCHANGEDB_ReserveExpiredCallback
                                           rec,
                                           TALER_EXCHANGEDB_RESERVE_EXPIRED_RESULT_CLOSURE
                                           *rec_cls);

#endif
