/*
  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 Lesser General Public License as published by the Free Software
  Foundation; either version 2.1, 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 Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public License along with
  TALER; see the file COPYING.LGPL.  If not, see
  <http://www.gnu.org/licenses/>
*/
/**
 * @file include/taler/taler-merchant/get-config.h
 * @brief C interface for GET /config of the merchant backend
 * @author Christian Grothoff
 */
#ifndef _TALER_MERCHANT__GET_CONFIG_H
#define _TALER_MERCHANT__GET_CONFIG_H

#include <taler/taler-merchant/common.h>


/**
 * Handle for a GET /config request.
 */
struct TALER_MERCHANT_ConfigGetHandle;


/**
 * Version compatibility status for the merchant backend.
 */
enum TALER_MERCHANT_VersionCompatibility
{
  /**
   * The client and server are at the same version.
   */
  TALER_MERCHANT_VC_MATCH = 0,

  /**
   * The server is running a newer API version.
   */
  TALER_MERCHANT_VC_NEWER = 1,

  /**
   * The server is running an older API version.
   */
  TALER_MERCHANT_VC_OLDER = 2,

  /**
   * The versions are incompatible.
   */
  TALER_MERCHANT_VC_INCOMPATIBLE = 4,

  /**
   * A protocol error occurred.
   */
  TALER_MERCHANT_VC_PROTOCOL_ERROR = 8
};


/**
 * Information about an exchange as returned in the config response.
 */
struct TALER_MERCHANT_ExchangeConfigInfo
{

  /**
   * Base URL of the exchange.
   */
  const char *base_url;

  /**
   * Currency served by this exchange.
   */
  const char *currency;

  /**
   * Master public key of the exchange.
   */
  struct TALER_MasterPublicKeyP master_pub;

};


/**
 * Response details for a GET /config request.
 */
struct TALER_MERCHANT_ConfigResponse
{

  /**
   * HTTP response details.
   */
  struct TALER_MERCHANT_HttpResponse hr;

  /**
   * Details depending on the HTTP status code.
   */
  union
  {

    /**
     * Details on #MHD_HTTP_OK.
     */
    struct
    {

      /**
       * API version string.
       */
      const char *version;

      /**
       * Currency used by this merchant backend.
       */
      const char *currency;

      /**
       * Compatibility status with the client library.
       */
      enum TALER_MERCHANT_VersionCompatibility compat;

      /**
       * Number of exchanges in @a exchanges.
       */
      unsigned int num_exchanges;

      /**
       * Array of exchange configurations.
       */
      const struct TALER_MERCHANT_ExchangeConfigInfo *exchanges;

      /**
       * Number of currency specifications in @a cspecs.
       */
      unsigned int num_cspecs;

      /**
       * Array of currency specifications.
       */
      const struct TALER_CurrencySpecification *cspecs;

      /**
       * Currency information returned by the backend.
       */
      struct
      {
        /**
         * Currency string.
         */
        const char *currency;

        /**
         * Version string.
         */
        const char *version;
      } ci;

    } ok;

  } details;

};


/**
 * Callback for a GET /config request.
 *
 * @param cls closure
 * @param cr response details
 */
typedef void
(*TALER_MERCHANT_ConfigCallback)(
  void *cls,
  const struct TALER_MERCHANT_ConfigResponse *cr);


/**
 * Issue a GET /config request to the merchant backend.
 *
 * @param ctx CURL context to use
 * @param backend_url base URL of the merchant backend
 * @param config_cb callback to invoke with the result
 * @param config_cb_cls closure for @a config_cb
 * @return handle for the request, NULL on hard error
 */
struct TALER_MERCHANT_ConfigGetHandle *
TALER_MERCHANT_config_get (struct GNUNET_CURL_Context *ctx,
                           const char *backend_url,
                           TALER_MERCHANT_ConfigCallback config_cb,
                           void *config_cb_cls);


/**
 * Cancel a GET /config request.
 *
 * @param[in] vgh handle to cancel
 */
void
TALER_MERCHANT_config_get_cancel (
  struct TALER_MERCHANT_ConfigGetHandle *vgh);


#endif
