/*
  This file is part of TALER
  Copyright (C) 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-config.h
 * @brief C interface for GET /config
 * @author Christian Grothoff
 */
#ifndef _TALER_EXCHANGE__GET_CONFIG_H
#define _TALER_EXCHANGE__GET_CONFIG_H

#include <taler/exchange/common.h>

/**
 * Handle for an operation to GET /config.
 */
struct TALER_EXCHANGE_GetConfigHandle;


/**
 * Information about how a currency should be rendered.
 */
struct TALER_EXCHANGE_GetConfigCurrencySpecification
{
  /**
   * Name of the currency, e.g. "US Dollar".
   */
  const char *name;

  /**
   * Currency code, e.g. "USD".
   * @deprecated in protocol v18
   */
  const char *currency;

  /**
   * Number of fractional digits the user may enter after the decimal separator.
   */
  unsigned int num_fractional_input_digits;

  /**
   * Number of fractional digits to render in normal font and size.
   */
  unsigned int num_fractional_normal_digits;

  /**
   * Number of fractional digits to always render, padding with zeros as needed.
   */
  unsigned int num_fractional_trailing_zero_digits;

  /**
   * Map of powers-of-10 to alternative currency names/symbols, as JSON object.
   * Must always have an entry under "0" that defines the base name,
   * e.g. {"0": "€"} or {"0": "BTC", "-3": "mBTC"}.
   * Communicates the currency symbol to be used.
   */
  const json_t *alt_unit_names;

  /**
   * Array of common amounts that should be offered as display buttons.
   * The array should have four entries, but may have fewer or more.
   * Since protocol v30 rev 2.
   */
  const struct TALER_Amount *common_amounts;

  /**
   * Length of the @e common_amounts array.
   */
  size_t common_amounts_length;

};


/**
 * Response from a GET /config request.
 */
struct TALER_EXCHANGE_GetConfigResponse
{
  /**
   * HTTP response data.
   */
  struct TALER_EXCHANGE_HttpResponse hr;

  /**
   * Response details depending on HTTP status.
   */
  union
  {
    /**
     * Details if HTTP status is #MHD_HTTP_OK.
     */
    struct
    {
      /**
       * Protocol version of the exchange, libtool-style "current:revision:age".
       */
      const char *version;

      /**
       * Protocol name, always "taler-exchange".
       */
      const char *name;

      /**
       * Optional URN of the implementation.
       * Since protocol v18.
       */
      const char *implementation;

      /**
       * Currency supported by this exchange (e.g. "USD" or "EUR").
       */
      const char *currency;

      /**
       * Optional URL of a shopping site where this exchange's currency is used.
       * Since protocol v21.
       */
      const char *shopping_url;

      /**
       * Optional open banking gateway URL for wire-based withdrawals.
       * Since protocol v30.
       */
      const char *open_banking_gateway;

      /**
       * How wallets should render this currency.
       */
      struct TALER_EXCHANGE_GetConfigCurrencySpecification
        currency_specification;

      /**
       * NULL-terminated array of supported KYC requirement names.
       * @deprecated since protocol v24.
       */
      const char **supported_kyc_requirements;

      /**
       * Optional AML SPA dialect name that determines which forms and
       * statistics are available.
       * Since protocol v24.
       */
      const char *aml_spa_dialect;

    } ok;
  } details;

};


#ifndef TALER_EXCHANGE_GET_CONFIG_RESULT_CLOSURE
/**
 * Type of the closure used by
 * the #TALER_EXCHANGE_GetConfigCallback.
 */
#define TALER_EXCHANGE_GET_CONFIG_RESULT_CLOSURE void
#endif /* TALER_EXCHANGE_GET_CONFIG_RESULT_CLOSURE */

/**
 * Type of the function that receives the result of a
 * GET /config request.
 *
 * @param cls closure
 * @param result result returned by the HTTP server
 */
typedef void
(*TALER_EXCHANGE_GetConfigCallback)(
  TALER_EXCHANGE_GET_CONFIG_RESULT_CLOSURE *cls,
  const struct TALER_EXCHANGE_GetConfigResponse *result);


/**
 * Set up GET /config operation.
 * Note that you must explicitly start the operation after setup.
 *
 * @param ctx the context
 * @param url base URL of the exchange
 * @return handle to operation
 */
struct TALER_EXCHANGE_GetConfigHandle *
TALER_EXCHANGE_get_config_create (
  struct GNUNET_CURL_Context *ctx,
  const char *url);


/**
 * Start GET /config operation.
 *
 * @param[in,out] gch 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_config_start (
  struct TALER_EXCHANGE_GetConfigHandle *gch,
  TALER_EXCHANGE_GetConfigCallback cb,
  TALER_EXCHANGE_GET_CONFIG_RESULT_CLOSURE *cb_cls);


/**
 * Cancel GET /config operation.  This function must not be called
 * by clients after the TALER_EXCHANGE_GetConfigCallback has been invoked
 * (as in those cases it'll be called internally by the
 * implementation already).
 *
 * @param[in] gch operation to cancel
 */
void
TALER_EXCHANGE_get_config_cancel (
  struct TALER_EXCHANGE_GetConfigHandle *gch);


#endif /* _TALER_EXCHANGE__GET_CONFIG_H */
