/*
   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_deferral_by_wtid.h
 * @brief implementation of the get_aggregation_deferral_by_wtid function for Postgres
 * @author Christian Grothoff
 */
#ifndef EXCHANGE_DATABASE_GET_AGGREGATION_DEFERRAL_BY_WTID_H
#define EXCHANGE_DATABASE_GET_AGGREGATION_DEFERRAL_BY_WTID_H

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

/**
 * Obtain the exchange's most recent statement of why it has not executed the
 * wire transfer @a wtid.  Used by the auditor, which reads this out of its
 * replica; `aggregation_deferrals` is append-only, so the row with the
 * greatest serial ID is the claim in force.
 *
 * Returns #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if the exchange never said
 * anything about @a wtid, which for a transfer that is still pending means
 * the exchange is simply not paying.
 *
 * @param pg the database context
 * @param wtid wire transfer to look up
 * @param[out] amount set to the amount the exchange said it was withholding
 * @param[out] reason set to the reason the exchange gave
 * @param[out] kyc_requirement_row set to the legitimization measure the
 *        exchange named, or 0 if it named none
 * @param[out] deferral_time set to when the exchange made the decision
 * @return transaction status
 */
enum GNUNET_DB_QueryStatus
TALER_EXCHANGEDB_get_aggregation_deferral_by_wtid (
  struct TALER_EXCHANGEDB_PostgresContext *pg,
  const struct TALER_WireTransferIdentifierRawP *wtid,
  struct TALER_Amount *amount,
  enum TALER_EXCHANGEDB_DeferralReason *reason,
  uint64_t *kyc_requirement_row,
  struct GNUNET_TIME_Timestamp *deferral_time);

#endif
