/*
  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 Lesser General Public License as published by the Free Software
  Foundation; either version 2.1, 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 Lesser General Public License for more details.

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

#include <taler/taler-merchant/common.h>


/**
 * Handle for a GET /private/transfers request.
 */
struct TALER_MERCHANT_GetTransfersHandle;


/**
 * Transfer data entry.
 */
struct TALER_MERCHANT_TransferData
{


  /**
   * Total amount wired by the exchange (without wire fee)
   */
  struct TALER_Amount credit_amount;

  /**
   * Wire transfer identifier used.
   */
  struct TALER_WireTransferIdentifierRawP wtid;

  /**
   * URI of the target account.
   */
  struct TALER_FullPayto payto_uri;

  /**
   * URL of the exchange that made the transfer.
   */
  const char *exchange_url;

  /**
   * Serial number of the credit operation in the merchant backend.
   * Needed, for example, to delete the transfer using
   * #TALER_MERCHANT_transfer_delete().
   */
  uint64_t credit_serial;

  /**
   * Time of the wire transfer, based on when we received
   * a confirmation for the wire transfer.
   */
  struct GNUNET_TIME_Timestamp execution_time;

  /**
   * True if this wire transfer was expected.
   */
  bool expected;

};


/**
 * Response details for a GET /private/transfers request.
 */
struct TALER_MERCHANT_GetTransfersResponse
{

  /**
   * HTTP response details.
   */
  struct TALER_MERCHANT_HttpResponse hr;

  /**
   * Details depending on the HTTP status code.
   */
  union
  {

    /**
     * Details on #MHD_HTTP_OK.
     */
    struct
    {

      /**
       * Number of transfers in @a transfers.
       */
      unsigned int transfers_length;

      /**
       * Array of transfer data entries.
       */
      const struct TALER_MERCHANT_TransferData *transfers;

    } ok;

  } details;

};


/**
 * Callback for a GET /private/transfers request.
 *
 * @param cls closure
 * @param gtr response details
 */
typedef void
(*TALER_MERCHANT_GetTransfersCallback)(
  void *cls,
  const struct TALER_MERCHANT_GetTransfersResponse *gtr);


/**
 * Issue a GET /private/transfers request.
 *
 * @param ctx CURL context to use
 * @param backend_url base URL of the merchant backend
 * @param payto_uri filter by payto URI (may be empty)
 * @param before filter for transfers before this time
 * @param after filter for transfers after this time
 * @param limit maximum number of results (negative for descending order)
 * @param offset pagination offset
 * @param expected filter by verification status
 * @param cb callback to invoke with the result
 * @param cb_cls closure for @a cb
 * @return handle for the request, NULL on hard error
 */
struct TALER_MERCHANT_GetTransfersHandle *
TALER_MERCHANT_transfers_get (
  struct GNUNET_CURL_Context *ctx,
  const char *backend_url,
  struct TALER_FullPayto payto_uri,
  const struct GNUNET_TIME_Timestamp before,
  const struct GNUNET_TIME_Timestamp after,
  int64_t limit,
  uint64_t offset,
  enum TALER_EXCHANGE_YesNoAll expected,
  TALER_MERCHANT_GetTransfersCallback cb,
  void *cb_cls);


/**
 * Cancel a GET /private/transfers request.
 *
 * @param[in] gth handle to cancel
 */
void
TALER_MERCHANT_transfers_get_cancel (
  struct TALER_MERCHANT_GetTransfersHandle *gth);


#endif
