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

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


/**
 * Obtain the deposits that were aggregated into the wire transfer @a wtid but
 * that the exchange has not (yet) executed, that is: for which there is no
 * `wire_out` row.
 *
 * The three totals are returned separately rather than netted out because the
 * exchange nets them out itself in `exchange_do_aggregate`, and the caller has
 * to be able to reproduce that arithmetic exactly: the amount the exchange
 * still owes is @a total_deposited - @a total_refunded - @a total_deposit_fee,
 * where the deposit fee is *not* charged for coins that were refunded in full.
 *
 * @param pg the database context
 * @param wtid wire transfer identifier to look up
 * @param[out] wire_target_h_payto set to the account the transfer should go to
 * @param[out] payto_uri set to the URI of that account, to be freed by the
 *        caller; needed because the normalized form of the account is not
 *        replicated to an external auditor
 * @param[out] total_deposited set to the sum of the deposited amounts
 * @param[out] total_refunded set to the sum of the refunded amounts
 * @param[out] total_deposit_fee set to the sum of the deposit fees charged
 * @return #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if the transfer was executed,
 *         or if no deposit was aggregated into @a wtid at all
 */
enum GNUNET_DB_QueryStatus
TALER_EXCHANGEDB_get_pending_aggregation (
  struct TALER_EXCHANGEDB_PostgresContext *pg,
  const struct TALER_WireTransferIdentifierRawP *wtid,
  struct TALER_FullPaytoHashP *wire_target_h_payto,
  struct TALER_FullPayto *payto_uri,
  struct TALER_Amount *total_deposited,
  struct TALER_Amount *total_refunded,
  struct TALER_Amount *total_deposit_fee);

#endif
