/*
  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/taler-exchange/post-management-drain.h
 * @brief C interface for POST /management/drain
 * @author Christian Grothoff
 */
#ifndef _TALER_EXCHANGE__POST_MANAGEMENT_DRAIN_H
#define _TALER_EXCHANGE__POST_MANAGEMENT_DRAIN_H

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

/**
 * Handle for an operation to POST /management/drain.
 */
struct TALER_EXCHANGE_PostManagementDrainHandle;


/**
 * Set up POST /management/drain operation.
 * Note that you must explicitly start the operation after setup.
 *
 * @param ctx the context
 * @param url HTTP base URL for the exchange
 * @param wtid wire transfer identifier to use
 * @param amount total to transfer
 * @param date when was the request created
 * @param account_section configuration section identifying account to debit
 * @param payto_uri RFC 8905 URI of the account to credit
 * @param master_sig signature affirming the operation
 * @return handle to operation, NULL on error
 */
struct TALER_EXCHANGE_PostManagementDrainHandle *
TALER_EXCHANGE_post_management_drain_create (
  struct GNUNET_CURL_Context *ctx,
  const char *url,
  const struct TALER_WireTransferIdentifierRawP *wtid,
  const struct TALER_Amount *amount,
  struct GNUNET_TIME_Timestamp date,
  const char *account_section,
  const struct TALER_FullPayto payto_uri,
  const struct TALER_MasterSignatureP *master_sig);


/**
 * Response from a POST /management/drain request.
 */
struct TALER_EXCHANGE_PostManagementDrainResponse
{
  /**
   * HTTP response data
   */
  struct TALER_EXCHANGE_HttpResponse hr;
};


#ifndef TALER_EXCHANGE_POST_MANAGEMENT_DRAIN_RESULT_CLOSURE
/**
 * Type of the closure used by
 * the #TALER_EXCHANGE_PostManagementDrainCallback.
 */
#define TALER_EXCHANGE_POST_MANAGEMENT_DRAIN_RESULT_CLOSURE void
#endif /* TALER_EXCHANGE_POST_MANAGEMENT_DRAIN_RESULT_CLOSURE */

/**
 * Type of the function that receives the result of a
 * POST /management/drain request.
 *
 * @param cls closure
 * @param result result returned by the HTTP server
 */
typedef void
(*TALER_EXCHANGE_PostManagementDrainCallback)(
  TALER_EXCHANGE_POST_MANAGEMENT_DRAIN_RESULT_CLOSURE *cls,
  const struct TALER_EXCHANGE_PostManagementDrainResponse *result);


/**
 * Start POST /management/drain operation.
 *
 * @param[in,out] pmdh 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_post_management_drain_start (
  struct TALER_EXCHANGE_PostManagementDrainHandle *pmdh,
  TALER_EXCHANGE_PostManagementDrainCallback cb,
  TALER_EXCHANGE_POST_MANAGEMENT_DRAIN_RESULT_CLOSURE *cb_cls);


/**
 * Cancel POST /management/drain operation.  This function must not be
 * called by clients after the TALER_EXCHANGE_PostManagementDrainCallback
 * has been invoked (as in those cases it'll be called internally by the
 * implementation already).
 *
 * @param[in] pmdh operation to cancel
 */
void
TALER_EXCHANGE_post_management_drain_cancel (
  struct TALER_EXCHANGE_PostManagementDrainHandle *pmdh);



#endif /* _TALER_EXCHANGE__POST_MANAGEMENT_DRAIN_H */
