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

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


/**
 * Obtain what the exchange itself says about a wire transfer it has aggregated
 * but not executed: how much it is holding, and whether it is holding it for
 * legitimization reasons.
 *
 * `aggregation_transient` is updated in place and deleted on payout, so it has
 * no serial ID and `taler-auditor-sync` cannot replicate it.  This is
 * therefore only usable for an exchange-internal audit (`-i`), where it serves
 * to check the auditor's own inference about the account against the reason
 * the exchange actually recorded.
 *
 * @param pg the database context
 * @param wire_target_h_payto account the transfer should go to
 * @param wtid wire transfer identifier to look up
 * @param[out] amount set to the amount the exchange says it is holding
 * @param[out] legitimization_measure_serial_id set to the measure the exchange
 *        is waiting for, or 0 if the exchange claims no legitimization reason
 * @return #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if the exchange has no
 *         transient aggregation for @a wtid
 */
enum GNUNET_DB_QueryStatus
TALER_EXCHANGEDB_get_aggregation_transient_by_wtid (
  struct TALER_EXCHANGEDB_PostgresContext *pg,
  const struct TALER_FullPaytoHashP *wire_target_h_payto,
  const struct TALER_WireTransferIdentifierRawP *wtid,
  struct TALER_Amount *amount,
  uint64_t *legitimization_measure_serial_id);

#endif
