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

#include <taler/merchant/common.h>


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


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

  /**
   * 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;

  /**
   * Website URL of the instance, or NULL if not set.
   */
  const char *website;

  /**
   * Logo (data URL) of the instance, or NULL if not set.
   */
  const char *logo;

  /**
   * True if this instance has been deleted.
   */
  bool deleted;

};


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

  /**
   * 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_GetManagementInstancesInstanceInfo *iis;

    } ok;

  } details;

};


/**
 * Set up GET /management/instances operation.
 * Note that you must explicitly start the operation after
 * possibly setting options.
 *
 * @param ctx the context
 * @param url base URL of the merchant backend
 * @return handle to operation
 */
struct TALER_MERCHANT_GetManagementInstancesHandle *
TALER_MERCHANT_get_management_instances_create (
  struct GNUNET_CURL_Context *ctx,
  const char *url);


#ifndef TALER_MERCHANT_GET_MANAGEMENT_INSTANCES_RESULT_CLOSURE
/**
 * Type of the closure used by
 * the #TALER_MERCHANT_GetManagementInstancesCallback.
 */
#define TALER_MERCHANT_GET_MANAGEMENT_INSTANCES_RESULT_CLOSURE void
#endif /* TALER_MERCHANT_GET_MANAGEMENT_INSTANCES_RESULT_CLOSURE */

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


/**
 * Start GET /management/instances operation.
 *
 * @param[in,out] gimh operation to start
 * @param cb function to call with the merchant's result
 * @param cb_cls closure for @a cb
 * @return status code, #TALER_EC_NONE on success
 */
enum TALER_ErrorCode
TALER_MERCHANT_get_management_instances_start (
  struct TALER_MERCHANT_GetManagementInstancesHandle *gimh,
  TALER_MERCHANT_GetManagementInstancesCallback cb,
  TALER_MERCHANT_GET_MANAGEMENT_INSTANCES_RESULT_CLOSURE *cb_cls);


/**
 * Cancel GET /management/instances operation.  This function must not be
 * called by clients after the TALER_MERCHANT_GetManagementInstancesCallback
 * has been invoked (as in those cases it'll be called internally by the
 * implementation already).
 *
 * @param[in] gimh operation to cancel
 */
void
TALER_MERCHANT_get_management_instances_cancel (
  struct TALER_MERCHANT_GetManagementInstancesHandle *gimh);


#endif /* _TALER_MERCHANT__GET_MANAGEMENT_INSTANCES_H */
