/*
  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/get-kyc-proof-PROVIDER_NAME.h
 * @brief C interface for GET /kyc-proof/$PROVIDER_NAME
 * @author Christian Grothoff
 */
#ifndef _TALER_EXCHANGE__GET_KYC_PROOF_PROVIDER_NAME_H
#define _TALER_EXCHANGE__GET_KYC_PROOF_PROVIDER_NAME_H

#include <taler/exchange/common.h>

/**
 * Possible options we can set for the GET kyc-proof request.
 */
enum TALER_EXCHANGE_GetKycProofOption
{
  /**
   * End of list of options.
   */
  TALER_EXCHANGE_GET_KYC_PROOF_OPTION_END = 0,

  /**
   * Additional arguments to append to the URL (must begin with '&').
   * Used to pass provider-specific query parameters.
   */
  TALER_EXCHANGE_GET_KYC_PROOF_OPTION_ARGS

};


/**
 * Value for an option for the GET kyc-proof request.
 */
struct TALER_EXCHANGE_GetKycProofOptionValue
{
  /**
   * Type of the option being set.
   */
  enum TALER_EXCHANGE_GetKycProofOption option;

  /**
   * Specific option value.
   */
  union
  {
    /**
     * Value if @e option is TALER_EXCHANGE_GET_KYC_PROOF_OPTION_ARGS.
     * Additional query string to append to the URL. Must begin with '&'.
     * The string must remain valid for the lifetime of the operation.
     */
    const char *args;

  } details;

};


/**
 * Handle for an operation to GET /kyc-proof/$PROVIDER_NAME.
 */
struct TALER_EXCHANGE_GetKycProofHandle;


/**
 * Set up GET /kyc-proof/$PROVIDER_NAME operation.
 * Note that you must explicitly start the operation after
 * possibly setting options.
 *
 * @param ctx the context
 * @param url base URL of the exchange
 * @param h_payto hash of the payto URI identifying the target account
 * @param logic name of the KYC logic / provider to use
 * @return handle to operation
 */
struct TALER_EXCHANGE_GetKycProofHandle *
TALER_EXCHANGE_get_kyc_proof_create (
  struct GNUNET_CURL_Context *ctx,
  const char *url,
  const struct TALER_NormalizedPaytoHashP *h_payto,
  const char *logic);


/**
 * Terminate the list of options.
 *
 * @return the terminating object of struct TALER_EXCHANGE_GetKycProofOptionValue
 */
#define TALER_EXCHANGE_get_kyc_proof_option_end_()                   \
        (const struct TALER_EXCHANGE_GetKycProofOptionValue)         \
        {                                                             \
          .option = TALER_EXCHANGE_GET_KYC_PROOF_OPTION_END          \
        }

/**
 * Set additional query string arguments to append to the URL.
 *
 * @param a additional args string, must begin with '&', must remain valid
 *          for the lifetime of the operation
 * @return representation of the option as a struct TALER_EXCHANGE_GetKycProofOptionValue
 */
#define TALER_EXCHANGE_get_kyc_proof_option_args(a)                    \
        (const struct TALER_EXCHANGE_GetKycProofOptionValue)           \
        {                                                               \
          .option = TALER_EXCHANGE_GET_KYC_PROOF_OPTION_ARGS,          \
          .details.args = (a)                                           \
        }


/**
 * Set the requested options for the operation.
 *
 * If any option fails, other options may or may not be applied.
 *
 * @param gkph the request to set the options for
 * @param num_options length of the @a options array
 * @param options an array of options
 * @return #GNUNET_OK on success,
 *         #GNUNET_NO on failure,
 *         #GNUNET_SYSERR on internal error
 */
enum GNUNET_GenericReturnValue
TALER_EXCHANGE_get_kyc_proof_set_options_ (
  struct TALER_EXCHANGE_GetKycProofHandle *gkph,
  unsigned int num_options,
  const struct TALER_EXCHANGE_GetKycProofOptionValue *options);


/**
 * Set the requested options for the operation.
 *
 * If any option fails, other options may or may not be applied.
 *
 * It should be used with helpers that create required options, for example:
 *
 * TALER_EXCHANGE_get_kyc_proof_set_options (
 *   gkph,
 *   TALER_EXCHANGE_get_kyc_proof_option_args ("&state=xyz"));
 *
 * @param gkph the request to set the options for
 * @param ... the list of options, each created by a
 *            TALER_EXCHANGE_get_kyc_proof_option_NAME(VALUE) helper
 * @return #GNUNET_OK on success,
 *         #GNUNET_NO on failure,
 *         #GNUNET_SYSERR on internal error
 */
#define TALER_EXCHANGE_get_kyc_proof_set_options(gkph,...)              \
        TALER_EXCHANGE_get_kyc_proof_set_options_ (                     \
          gkph,                                                          \
          TALER_EXCHANGE_COMMON_OPTIONS_ARRAY_MAX_SIZE,                  \
          ((const struct TALER_EXCHANGE_GetKycProofOptionValue[])        \
           {__VA_ARGS__, TALER_EXCHANGE_get_kyc_proof_option_end_ () }   \
          ))


/**
 * Response from a GET /kyc-proof/$PROVIDER_NAME request.
 */
struct TALER_EXCHANGE_GetKycProofResponse
{
  /**
   * HTTP response data.
   */
  struct TALER_EXCHANGE_HttpResponse hr;

  /**
   * Details depending on HTTP status.
   */
  union
  {
    /**
     * Details on #MHD_HTTP_SEE_OTHER (redirect).
     */
    struct
    {
      /**
       * URL to redirect the client to next.
       */
      const char *redirect_url;

    } see_other;

  } details;

};


#ifndef TALER_EXCHANGE_GET_KYC_PROOF_RESULT_CLOSURE
/**
 * Type of the closure used by
 * the #TALER_EXCHANGE_GetKycProofCallback.
 */
#define TALER_EXCHANGE_GET_KYC_PROOF_RESULT_CLOSURE void
#endif /* TALER_EXCHANGE_GET_KYC_PROOF_RESULT_CLOSURE */

/**
 * Type of the function that receives the result of a
 * GET /kyc-proof/$PROVIDER_NAME request.
 *
 * @param cls closure
 * @param result result returned by the HTTP server
 */
typedef void
(*TALER_EXCHANGE_GetKycProofCallback)(
  TALER_EXCHANGE_GET_KYC_PROOF_RESULT_CLOSURE *cls,
  const struct TALER_EXCHANGE_GetKycProofResponse *result);


/**
 * Start GET /kyc-proof/$PROVIDER_NAME operation.
 *
 * @param[in,out] gkph 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_get_kyc_proof_start (
  struct TALER_EXCHANGE_GetKycProofHandle *gkph,
  TALER_EXCHANGE_GetKycProofCallback cb,
  TALER_EXCHANGE_GET_KYC_PROOF_RESULT_CLOSURE *cb_cls);


/**
 * Cancel GET /kyc-proof/$PROVIDER_NAME operation.  This function must not
 * be called by clients after the TALER_EXCHANGE_GetKycProofCallback has been
 * invoked (as in those cases it'll be called internally by the
 * implementation already).
 *
 * @param[in] gkph operation to cancel
 */
void
TALER_EXCHANGE_get_kyc_proof_cancel (
  struct TALER_EXCHANGE_GetKycProofHandle *gkph);


#endif /* _TALER_EXCHANGE__GET_KYC_PROOF_PROVIDER_NAME_H */
