/*
  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-kyc-wallet.h
 * @brief C interface for POST /kyc-wallet
 * @author Christian Grothoff
 */
#ifndef _TALER_EXCHANGE__POST_KYC_WALLET_H
#define _TALER_EXCHANGE__POST_KYC_WALLET_H

#include <taler/exchange/common.h>

/**
 * Handle for an operation to POST /kyc-wallet.
 */
struct TALER_EXCHANGE_PostKycWalletHandle;


/**
 * Set up POST /kyc-wallet operation.
 * Note that you must explicitly start the operation after setup.
 *
 * @param ctx CURL context
 * @param url exchange base URL
 * @param reserve_priv wallet private key to check
 * @param balance balance (or balance threshold) crossed by the wallet
 * @return handle to operation, NULL on error
 */
struct TALER_EXCHANGE_PostKycWalletHandle *
TALER_EXCHANGE_post_kyc_wallet_create (
  struct GNUNET_CURL_Context *ctx,
  const char *url,
  const struct TALER_ReservePrivateKeyP *reserve_priv,
  const struct TALER_Amount *balance);


/**
 * KYC wallet status response details.
 */
struct TALER_EXCHANGE_PostKycWalletResponse
{
  /**
   * HTTP response data
   */
  struct TALER_EXCHANGE_HttpResponse hr;

  /**
   * Variants depending on @e hr.http_status.
   */
  union
  {
    struct
    {
      /**
       * Above which amount does the wallet need to check
       * for KYC again?
       */
      struct TALER_Amount next_threshold;

      /**
       * When will the current set of AML/KYC rules
       * expire (and the wallet should again check
       * for new KYC requirements)?
       */
      struct GNUNET_TIME_Timestamp expiration_time;

    } ok;

    /**
     * Details if the status is #MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS.
     */
    struct TALER_EXCHANGE_KycNeededRedirect unavailable_for_legal_reasons;

  } details;

};


#ifndef TALER_EXCHANGE_POST_KYC_WALLET_RESULT_CLOSURE
/**
 * Type of the closure used by
 * the #TALER_EXCHANGE_PostKycWalletCallback.
 */
#define TALER_EXCHANGE_POST_KYC_WALLET_RESULT_CLOSURE void
#endif /* TALER_EXCHANGE_POST_KYC_WALLET_RESULT_CLOSURE */

/**
 * Type of the function that receives the result of a
 * POST /kyc-wallet request.
 *
 * @param cls closure
 * @param result result returned by the HTTP server
 */
typedef void
(*TALER_EXCHANGE_PostKycWalletCallback)(
  TALER_EXCHANGE_POST_KYC_WALLET_RESULT_CLOSURE *cls,
  const struct TALER_EXCHANGE_PostKycWalletResponse *result);


/**
 * Start POST /kyc-wallet operation.
 *
 * @param[in,out] pkwh 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_kyc_wallet_start (
  struct TALER_EXCHANGE_PostKycWalletHandle *pkwh,
  TALER_EXCHANGE_PostKycWalletCallback cb,
  TALER_EXCHANGE_POST_KYC_WALLET_RESULT_CLOSURE *cb_cls);


/**
 * Cancel POST /kyc-wallet operation.  This function must not be called by
 * clients after the TALER_EXCHANGE_PostKycWalletCallback has been invoked
 * (as in those cases it'll be called internally by the implementation
 * already).
 *
 * @param[in] pkwh operation to cancel
 */
void
TALER_EXCHANGE_post_kyc_wallet_cancel (
  struct TALER_EXCHANGE_PostKycWalletHandle *pkwh);


#endif /* _TALER_EXCHANGE__POST_KYC_WALLET_H */
