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

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


/**
 * Function called on (batch) deposits will need a wire
 * transfer.
 *
 * @param cls closure
 * @param batch_deposit_serial_id where in the table are we
 * @param total_amount value of all missing deposits, including fees
 * @param wire_target_h_payto hash of the recipient account's payto URI
 * @param deadline what was the earliest requested wire transfer deadline
 */
#ifndef TALER_EXCHANGEDB_WIRE_MISSING_RESULT_CLOSURE
/**
 * Type of the closure for #TALER_EXCHANGEDB_WireMissingCallback.
 */
#define TALER_EXCHANGEDB_WIRE_MISSING_RESULT_CLOSURE void
#endif
typedef void
(*TALER_EXCHANGEDB_WireMissingCallback)(
  TALER_EXCHANGEDB_WIRE_MISSING_RESULT_CLOSURE *cls,
  uint64_t batch_deposit_serial_id,
  const struct TALER_Amount *total_amount,
  const struct TALER_FullPaytoHashP *wire_target_h_payto,
  struct GNUNET_TIME_Timestamp deadline);


/* Callback typedefs */
/**
 * Function called on (batch) deposits will need a wire
 * transfer.
 *
 * @param cls closure
 * @param batch_deposit_serial_id where in the table are we
 * @param total_amount value of all missing deposits, including fees
 * @param wire_target_h_payto hash of the recipient account's payto URI
 * @param deadline what was the earliest requested wire transfer deadline
 */
typedef void
(*TALER_EXCHANGEDB_WireMissingCallback)(
  TALER_EXCHANGEDB_WIRE_MISSING_RESULT_CLOSURE *cls,
  uint64_t batch_deposit_serial_id,
  const struct TALER_Amount *total_amount,
  const struct TALER_FullPaytoHashP *wire_target_h_payto,
  struct GNUNET_TIME_Timestamp deadline);

/**
 * Select all of those batch deposits in the database
 * above the given serial ID.
 *
 * @param pg the database context
 * @param min_batch_deposit_serial_id select all batch deposits above this ID
 * @param cb function to call on all such deposits
 * @param cb_cls closure for @a cb
 * @return transaction status code
 */
enum GNUNET_DB_QueryStatus
TALER_EXCHANGEDB_iterate_batch_deposits_missing_wire (struct
                                                      TALER_EXCHANGEDB_PostgresContext
                                                      *pg,
                                                      uint64_t
                                                      min_batch_deposit_serial_id,
                                                      TALER_EXCHANGEDB_WireMissingCallback
                                                      cb,
                                                      TALER_EXCHANGEDB_WIRE_MISSING_RESULT_CLOSURE
                                                      *cb_cls);

#endif
