/*
  This file is part of TALER
  Copyright (C) 2014-2026 Taler Systems SA

  TALER is free software; you can redistribute it and/or modify it under the
  terms of the GNU Affero 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 Affero General Public License for more details.

  You should have received a copy of the GNU Affero General Public License along with
  TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
 */
/**
 * @file include/taler/exchange/get-transfers-WTID.h
 * @brief C interface for GET /transfers/$WTID
 * @author Christian Grothoff
 */
#ifndef _TALER_EXCHANGE__GET_TRANSFERS_WTID_H
#define _TALER_EXCHANGE__GET_TRANSFERS_WTID_H

#include <taler/exchange/common.h>

/**
 * Handle for an operation to GET /transfers/$WTID.
 */
struct TALER_EXCHANGE_GetTransfersHandle;


/**
 * Information the exchange returns per wire transfer.
 */
struct TALER_EXCHANGE_TransferData
{
  /**
   * Exchange key used to sign.
   */
  struct TALER_ExchangePublicKeyP exchange_pub;

  /**
   * Exchange signature over the transfer data.
   */
  struct TALER_ExchangeSignatureP exchange_sig;

  /**
   * Hash of the payto:// URI the transfer went to.
   */
  struct TALER_FullPaytoHashP h_payto;

  /**
   * Time when the exchange claims to have performed the wire transfer.
   */
  struct GNUNET_TIME_Timestamp execution_time;

  /**
   * Actual amount of the wire transfer, excluding the wire fee.
   */
  struct TALER_Amount total_amount;

  /**
   * Wire fee that was charged by the exchange.
   */
  struct TALER_Amount wire_fee;

  /**
   * Length of the @e details array.
   */
  unsigned int details_length;

  /**
   * Array with details about the combined transactions.
   */
  const struct TALER_TrackTransferDetails *details;

  /**
   * Hash over all of the @e details, for signature verification.
   */
  struct GNUNET_HashCode h_details;

  /**
   * Public key of the merchant (to identify who this transfer was for).
   */
  struct TALER_MerchantPublicKeyP merchant_pub;

};


/**
 * Response from a GET /transfers/$WTID request.
 */
struct TALER_EXCHANGE_GetTransfersResponse
{
  /**
   * HTTP response data.
   */
  struct TALER_EXCHANGE_HttpResponse hr;

  /**
   * Details depending on HTTP status code.
   */
  union
  {
    /**
     * Details if HTTP status is #MHD_HTTP_OK.
     */
    struct
    {
      /**
       * Transfer details.
       */
      struct TALER_EXCHANGE_TransferData td;
    } ok;

  } details;

};


#ifndef TALER_EXCHANGE_GET_TRANSFERS_RESULT_CLOSURE
/**
 * Type of the closure used by
 * the #TALER_EXCHANGE_GetTransfersCallback.
 */
#define TALER_EXCHANGE_GET_TRANSFERS_RESULT_CLOSURE void
#endif /* TALER_EXCHANGE_GET_TRANSFERS_RESULT_CLOSURE */

/**
 * Type of the function that receives the result of a
 * GET /transfers/$WTID request.
 *
 * @param cls closure
 * @param result result returned by the HTTP server
 */
typedef void
(*TALER_EXCHANGE_GetTransfersCallback)(
  TALER_EXCHANGE_GET_TRANSFERS_RESULT_CLOSURE *cls,
  const struct TALER_EXCHANGE_GetTransfersResponse *result);


/**
 * Set up GET /transfers/$WTID operation.
 * Note that you must explicitly start the operation after setup.
 *
 * @param ctx the context
 * @param url base URL of the exchange
 * @param keys exchange keys for signature verification
 * @param wtid raw wire transfer identifier to look up
 * @return handle to operation
 */
struct TALER_EXCHANGE_GetTransfersHandle *
TALER_EXCHANGE_get_transfers_create (
  struct GNUNET_CURL_Context *ctx,
  const char *url,
  struct TALER_EXCHANGE_Keys *keys,
  const struct TALER_WireTransferIdentifierRawP *wtid);


/**
 * Start GET /transfers/$WTID operation.
 *
 * @param[in,out] gth operation to start
 * @param cb function to call with the exchange's result
 * @param cb_cls closure for @a cb
 * @return status code, #TALER_EC_NONE on success
 */
enum TALER_ErrorCode
TALER_EXCHANGE_get_transfers_start (
  struct TALER_EXCHANGE_GetTransfersHandle *gth,
  TALER_EXCHANGE_GetTransfersCallback cb,
  TALER_EXCHANGE_GET_TRANSFERS_RESULT_CLOSURE *cb_cls);


/**
 * Cancel GET /transfers/$WTID operation.  This function must not be called
 * by clients after the TALER_EXCHANGE_GetTransfersCallback has been invoked
 * (as in those cases it'll be called internally by the
 * implementation already).
 *
 * @param[in] gth operation to cancel
 */
void
TALER_EXCHANGE_get_transfers_cancel (
  struct TALER_EXCHANGE_GetTransfersHandle *gth);


#endif /* _TALER_EXCHANGE__GET_TRANSFERS_WTID_H */
