/*
  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-management-instances.h
 * @brief C interface for GET /management/instances of the merchant backend
 * @author Christian Grothoff
 */
#ifndef _TALER_MERCHANT__GET_MANAGEMENT_INSTANCES_H
#define _TALER_MERCHANT__GET_MANAGEMENT_INSTANCES_H

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


/**
 * Handle for a GET /management/instances request.
 */
struct TALER_MERCHANT_InstancesGetHandle;


/**
 * Information about one merchant instance.
 */
struct TALER_MERCHANT_InstanceInformation
{

  /**
   * Instance identifier string.
   */
  const char *id;

  /**
   * Human-readable name of the instance.
   */
  const char *name;

  /**
   * Public key of the instance.
   */
  struct TALER_MerchantPublicKeyP merchant_pub;

  /**
   * JSON array of supported payment targets.
   */
  const json_t *payment_targets;

};


/**
 * Response details for a GET /management/instances request.
 */
struct TALER_MERCHANT_InstancesGetResponse
{

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

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

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

      /**
       * Number of instances in @a iis.
       */
      unsigned int iis_length;

      /**
       * Array of instance information.
       */
      const struct TALER_MERCHANT_InstanceInformation *iis;

    } ok;

  } details;

};


/**
 * Callback for a GET /management/instances request.
 *
 * @param cls closure
 * @param igr response details
 */
typedef void
(*TALER_MERCHANT_InstancesGetCallback)(
  void *cls,
  const struct TALER_MERCHANT_InstancesGetResponse *igr);


/**
 * Issue a GET /management/instances request.
 *
 * @param ctx CURL context to use
 * @param backend_url base URL of the merchant backend
 * @param instances_cb callback to invoke with the result
 * @param instances_cb_cls closure for @a instances_cb
 * @return handle for the request, NULL on hard error
 */
struct TALER_MERCHANT_InstancesGetHandle *
TALER_MERCHANT_instances_get (
  struct GNUNET_CURL_Context *ctx,
  const char *backend_url,
  TALER_MERCHANT_InstancesGetCallback instances_cb,
  void *instances_cb_cls);


/**
 * Cancel a GET /management/instances request.
 *
 * @param[in] igh handle to cancel
 */
void
TALER_MERCHANT_instances_get_cancel (
  struct TALER_MERCHANT_InstancesGetHandle *igh);


#endif
