/*
  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-recoup-refresh.h
 * @brief C interface for POST /coins/$COIN_PUB/recoup-refresh
 * @author Christian Grothoff
 */
#ifndef _TALER_EXCHANGE__POST_RECOUP_REFRESH_H
#define _TALER_EXCHANGE__POST_RECOUP_REFRESH_H

#include <taler/exchange/common.h>

/**
 * Handle for an operation to POST /coins/$COIN_PUB/recoup-refresh.
 */
struct TALER_EXCHANGE_PostRecoupRefreshHandle;


/**
 * Set up POST /coins/$COIN_PUB/recoup-refresh operation.
 * Note that you must explicitly start the operation after setup.
 *
 * Ask the exchange to pay back a coin due to the exchange triggering
 * the emergency recoup protocol for a given denomination.  The value
 * of the coin will be refunded to the original coin that the
 * revoked coin was refreshed from. The original coin is then
 * considered a zombie.
 *
 * @param ctx curl context
 * @param url exchange base URL
 * @param keys exchange keys
 * @param pk kind of coin to pay back
 * @param denom_sig signature over the coin by the exchange using @a pk
 * @param exchange_vals contribution from the exchange on the withdraw
 * @param rms the public seed of the refreshing operation
 * @param ps coin-specific secrets derived for this coin during the refreshing operation
 * @param idx index of the fresh coin in the refresh operation that is now being recouped
 * @return handle to operation, NULL if the inputs are invalid
 */
struct TALER_EXCHANGE_PostRecoupRefreshHandle *
TALER_EXCHANGE_post_recoup_refresh_create (
  struct GNUNET_CURL_Context *ctx,
  const char *url,
  struct TALER_EXCHANGE_Keys *keys,
  const struct TALER_EXCHANGE_DenomPublicKey *pk,
  const struct TALER_DenominationSignature *denom_sig,
  const struct TALER_ExchangeBlindingValues *exchange_vals,
  const struct TALER_PublicRefreshMasterSeedP *rms,
  const struct TALER_PlanchetMasterSecretP *ps,
  unsigned int idx);


/**
 * Response from a POST /coins/$COIN_PUB/recoup-refresh request.
 */
struct TALER_EXCHANGE_PostRecoupRefreshResponse
{
  /**
   * HTTP response data
   */
  struct TALER_EXCHANGE_HttpResponse hr;

  /**
   * Response details depending on the HTTP status.
   */
  union
  {
    /**
     * Details if HTTP status is #MHD_HTTP_OK.
     */
    struct
    {
      /**
       * public key of the dirty coin that was credited
       */
      struct TALER_CoinSpendPublicKeyP old_coin_pub;

    } ok;
  } details;

};


#ifndef TALER_EXCHANGE_POST_RECOUP_REFRESH_RESULT_CLOSURE
/**
 * Type of the closure used by
 * the #TALER_EXCHANGE_PostRecoupRefreshCallback.
 */
#define TALER_EXCHANGE_POST_RECOUP_REFRESH_RESULT_CLOSURE void
#endif /* TALER_EXCHANGE_POST_RECOUP_REFRESH_RESULT_CLOSURE */

/**
 * Type of the function that receives the result of a
 * POST /coins/$COIN_PUB/recoup-refresh request.
 *
 * @param cls closure
 * @param result result returned by the HTTP server
 */
typedef void
(*TALER_EXCHANGE_PostRecoupRefreshCallback)(
  TALER_EXCHANGE_POST_RECOUP_REFRESH_RESULT_CLOSURE *cls,
  const struct TALER_EXCHANGE_PostRecoupRefreshResponse *result);


/**
 * Start POST /coins/$COIN_PUB/recoup-refresh operation.
 *
 * @param[in,out] prrh 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_recoup_refresh_start (
  struct TALER_EXCHANGE_PostRecoupRefreshHandle *prrh,
  TALER_EXCHANGE_PostRecoupRefreshCallback cb,
  TALER_EXCHANGE_POST_RECOUP_REFRESH_RESULT_CLOSURE *cb_cls);


/**
 * Cancel POST /coins/$COIN_PUB/recoup-refresh operation.  This function must
 * not be called by clients after the
 * TALER_EXCHANGE_PostRecoupRefreshCallback has been invoked (as in those
 * cases it'll be called internally by the implementation already).
 *
 * @param[in] prrh operation to cancel
 */
void
TALER_EXCHANGE_post_recoup_refresh_cancel (
  struct TALER_EXCHANGE_PostRecoupRefreshHandle *prrh);


#endif /* _TALER_EXCHANGE__POST_RECOUP_REFRESH_H */
