/*
  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-purses-PURSE_PUB-deposit.h
 * @brief C interface for POST /purses/$PURSE_PUB/deposit
 * @author Christian Grothoff
 */
#ifndef _TALER_EXCHANGE__POST_PURSES_PURSE_PUB_DEPOSIT_H
#define _TALER_EXCHANGE__POST_PURSES_PURSE_PUB_DEPOSIT_H

#include <taler/exchange/common.h>

/**
 * Handle for an operation to POST /purses/$PURSE_PUB/deposit.
 */
struct TALER_EXCHANGE_PostPursesDepositHandle;


/**
 * Set up POST /purses/$PURSE_PUB/deposit operation.
 * Note that you must explicitly start the operation after setup.
 *
 * @param ctx curl context
 * @param url exchange base URL
 * @param keys exchange keys
 * @param purse_exchange_url base URL of the exchange hosting the purse
 * @param purse_pub public key of the purse to deposit into
 * @param min_age minimum age we need to prove for the purse
 * @param num_deposits length of the @a deposits array
 * @param deposits array of deposits to make into the purse
 * @return handle to operation, NULL on error
 */
struct TALER_EXCHANGE_PostPursesDepositHandle *
TALER_EXCHANGE_post_purses_deposit_create (
  struct GNUNET_CURL_Context *ctx,
  const char *url,
  struct TALER_EXCHANGE_Keys *keys,
  const char *purse_exchange_url, // FIXME: turn into option
  const struct TALER_PurseContractPublicKeyP *purse_pub,
  uint8_t min_age, // FIXME:  turn into option
  unsigned int num_deposits,
  const struct TALER_EXCHANGE_PurseDeposit deposits[static num_deposits]);


/**
 * Response generated for purse deposit request.
 */
struct TALER_EXCHANGE_PostPursesDepositResponse
{
  /**
   * Full HTTP response.
   */
  struct TALER_EXCHANGE_HttpResponse hr;

  /**
   * Details depending on the HTTP status.
   */
  union
  {
    /**
     * Details returned on #MHD_HTTP_OK.
     */
    struct
    {
      /**
       * When does the purse expire.
       */
      struct GNUNET_TIME_Timestamp purse_expiration;

      /**
       * How much was actually deposited into the purse.
       */
      struct TALER_Amount total_deposited;

      /**
       * How much should be in the purse in total in the end.
       */
      struct TALER_Amount purse_value_after_fees;

      /**
       * Hash of the contract (needed to verify signature).
       */
      struct TALER_PrivateContractHashP h_contract_terms;

      /**
       * Signature by the exchange affirming the deposit.
       */
      struct TALER_ExchangeSignatureP exchange_sig;

      /**
       * Online signing key used by the exchange.
       */
      struct TALER_ExchangePublicKeyP exchange_pub;

    } ok;
  } details;

};


#ifndef TALER_EXCHANGE_POST_PURSES_DEPOSIT_RESULT_CLOSURE
/**
 * Type of the closure used by
 * the #TALER_EXCHANGE_PostPursesDepositCallback.
 */
#define TALER_EXCHANGE_POST_PURSES_DEPOSIT_RESULT_CLOSURE void
#endif /* TALER_EXCHANGE_POST_PURSES_DEPOSIT_RESULT_CLOSURE */

/**
 * Type of the function that receives the result of a
 * POST /purses/$PURSE_PUB/deposit request.
 *
 * @param cls closure
 * @param result result returned by the HTTP server
 */
typedef void
(*TALER_EXCHANGE_PostPursesDepositCallback)(
  TALER_EXCHANGE_POST_PURSES_DEPOSIT_RESULT_CLOSURE *cls,
  const struct TALER_EXCHANGE_PostPursesDepositResponse *result);


/**
 * Start POST /purses/$PURSE_PUB/deposit operation.
 *
 * @param[in,out] ppdh 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_purses_deposit_start (
  struct TALER_EXCHANGE_PostPursesDepositHandle *ppdh,
  TALER_EXCHANGE_PostPursesDepositCallback cb,
  TALER_EXCHANGE_POST_PURSES_DEPOSIT_RESULT_CLOSURE *cb_cls);


/**
 * Cancel POST /purses/$PURSE_PUB/deposit operation.  This function must not
 * be called by clients after the TALER_EXCHANGE_PostPursesDepositCallback has
 * been invoked (as in those cases it'll be called internally by the
 * implementation already).
 *
 * @param[in] ppdh operation to cancel
 */
void
TALER_EXCHANGE_post_purses_deposit_cancel (
  struct TALER_EXCHANGE_PostPursesDepositHandle *ppdh);


#endif /* _TALER_EXCHANGE__POST_PURSES_PURSE_PUB_DEPOSIT_H */
