/*
  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/post-reveal-withdraw.h
 * @brief C interface for POST /reveal-withdraw
 * @author Christian Grothoff
 */
#ifndef _TALER_EXCHANGE__POST_REVEAL_WITHDRAW_H
#define _TALER_EXCHANGE__POST_REVEAL_WITHDRAW_H

#include <taler/exchange/common.h>

/**
 * Handle for an operation to POST /reveal-withdraw.
 */
struct TALER_EXCHANGE_PostRevealWithdrawHandle;


/**
 * Set up POST /reveal-withdraw operation.
 * Note that you must explicitly start the operation after setup.
 *
 * This is required as the second step to a withdraw of age-restricted
 * coins with proof that the correct age-restriction has been applied.
 *
 * This API is typically used by a wallet.  Note that to ensure that
 * no money is lost in case of hardware failures, the provided
 * arguments should be committed to persistent storage
 * prior to calling this function.
 *
 * @param curl_ctx The curl context
 * @param exchange_url The base url of the exchange
 * @param num_coins Number of coin signatures to expect from the reveal
 * @param h_planchets The commitment from the previous call to withdraw
 * @param seeds TALER_CNC_KAPPA-1 tuple of seeds to reveal
 * @return handle to operation, NULL on error
 */
struct TALER_EXCHANGE_PostRevealWithdrawHandle *
TALER_EXCHANGE_post_reveal_withdraw_create (
  struct GNUNET_CURL_Context *curl_ctx,
  const char *exchange_url,
  size_t num_coins,
  const struct TALER_HashBlindedPlanchetsP *h_planchets,
  const struct TALER_RevealWithdrawMasterSeedsP *seeds);


/**
 * The response from a POST /reveal-withdraw request.
 */
struct TALER_EXCHANGE_PostRevealWithdrawResponse
{
  /**
   * HTTP response data.
   */
  struct TALER_EXCHANGE_HttpResponse hr;

  /**
   * Details about the response
   */
  union
  {
    /**
     * Details if the status is #MHD_HTTP_OK.
     */
    struct
    {
      /**
       * Number of signatures returned.
       */
      unsigned int num_sigs;

      /**
       * Array of @e num_sigs blinded denomination signatures, giving each
       * coin its value and validity. The array gives these coins in the same
       * order (and should have the same length) in which the original
       * withdraw request specified the respective denomination keys.
       */
      const struct TALER_BlindedDenominationSignature *blinded_denom_sigs;

    } ok;

  } details;

};


#ifndef TALER_EXCHANGE_POST_REVEAL_WITHDRAW_RESULT_CLOSURE
/**
 * Type of the closure used by
 * the #TALER_EXCHANGE_PostRevealWithdrawCallback.
 */
#define TALER_EXCHANGE_POST_REVEAL_WITHDRAW_RESULT_CLOSURE void
#endif /* TALER_EXCHANGE_POST_REVEAL_WITHDRAW_RESULT_CLOSURE */

/**
 * Type of the function that receives the result of a
 * POST /reveal-withdraw request.
 *
 * @param cls closure
 * @param result result returned by the HTTP server
 */
typedef void
(*TALER_EXCHANGE_PostRevealWithdrawCallback)(
  TALER_EXCHANGE_POST_REVEAL_WITHDRAW_RESULT_CLOSURE *cls,
  const struct TALER_EXCHANGE_PostRevealWithdrawResponse *result);


/**
 * Start POST /reveal-withdraw operation.
 *
 * @param[in,out] prwh 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_reveal_withdraw_start (
  struct TALER_EXCHANGE_PostRevealWithdrawHandle *prwh,
  TALER_EXCHANGE_PostRevealWithdrawCallback cb,
  TALER_EXCHANGE_POST_REVEAL_WITHDRAW_RESULT_CLOSURE *cb_cls);


/**
 * Cancel POST /reveal-withdraw operation.  This function must not be called
 * by clients after the TALER_EXCHANGE_PostRevealWithdrawCallback has been
 * invoked (as in those cases it'll be called internally by the implementation
 * already).
 *
 * @param[in] prwh operation to cancel
 */
void
TALER_EXCHANGE_post_reveal_withdraw_cancel (
  struct TALER_EXCHANGE_PostRevealWithdrawHandle *prwh);


#endif /* _TALER_EXCHANGE__POST_REVEAL_WITHDRAW_H */
