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

#include <taler/merchant/common.h>


/**
 * Handle for a GET /management/instances/$INSTANCE request.
 */
struct TALER_MERCHANT_GetManagementInstanceHandle;


/**
 * Account details for a merchant wire account
 * as returned by GET /management/instances/$INSTANCE.
 */
struct TALER_MERCHANT_ManagementAccountEntry
{

  /**
   * Full payto URI of the account.
   */
  struct TALER_FullPayto payto_uri;

  /**
   * URL of the credit facade (optional, may be NULL).
   */
  const char *credit_facade_url;

  /**
   * Hash of the wire details.
   */
  struct TALER_MerchantWireHashP h_wire;

  /**
   * Salt used to compute @e h_wire.
   */
  struct TALER_WireSaltP salt;

  /**
   * True if the account is active.
   */
  bool active;

};


/**
 * Detailed information about a merchant instance.
 */
struct TALER_MERCHANT_GetManagementInstanceDetails
{

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

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

  /**
   * Whether to use the STEFAN curve for fee calculations.
   */
  bool use_stefan;

  /**
   * Default wire transfer delay.
   */
  struct GNUNET_TIME_Relative default_wire_transfer_delay;

  /**
   * Default payment deadline.
   */
  struct GNUNET_TIME_Relative default_pay_delay;

  /**
   * Default refund deadline.
   */
  struct GNUNET_TIME_Relative default_refund_delay;

  /**
   * Default wire transfer rounding interval.
   */
  enum GNUNET_TIME_RounderInterval default_wire_transfer_rounding_interval;

  /**
   * Merchant address (JSON).
   */
  const json_t *address;

  /**
   * Merchant jurisdiction (JSON).
   */
  const json_t *jurisdiction;

  /**
   * Email address of the merchant (optional, may be NULL).
   */
  const char *email;

  /**
   * Whether the email address has been validated.
   * Only meaningful if @e email is not NULL.
   */
  bool email_validated;

  /**
   * Phone number of the merchant (optional, may be NULL).
   */
  const char *phone_number;

  /**
   * Whether the phone number has been validated.
   * Only meaningful if @e phone_number is not NULL.
   */
  bool phone_validated;

  /**
   * Website URL of the merchant (optional, may be NULL).
   */
  const char *website;

  /**
   * Logo of the merchant (optional, may be NULL).
   */
  const char *logo;

};


/**
 * Response details for a GET /management/instances/$INSTANCE request.
 */
struct TALER_MERCHANT_GetManagementInstanceResponse
{

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

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

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

      /**
       * Detailed information about the instance.
       */
      struct TALER_MERCHANT_GetManagementInstanceDetails details;

      /**
       * Number of accounts in @a accounts.
       */
      unsigned int accounts_length;

      /**
       * Array of account entries.
       */
      const struct TALER_MERCHANT_ManagementAccountEntry *accounts;

    } ok;

  } details;

};


/**
 * Set up GET /management/instances/$INSTANCE 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
 * @param instance_id identifier of the instance to retrieve,
 *        NULL for admin instance
 * @return handle to operation
 */
struct TALER_MERCHANT_GetManagementInstanceHandle *
TALER_MERCHANT_get_management_instance_create (
  struct GNUNET_CURL_Context *ctx,
  const char *url,
  const char *instance_id);


#ifndef TALER_MERCHANT_GET_MANAGEMENT_INSTANCE_RESULT_CLOSURE
/**
 * Type of the closure used by
 * the #TALER_MERCHANT_GetManagementInstanceCallback.
 */
#define TALER_MERCHANT_GET_MANAGEMENT_INSTANCE_RESULT_CLOSURE void
#endif /* TALER_MERCHANT_GET_MANAGEMENT_INSTANCE_RESULT_CLOSURE */

/**
 * Callback for a GET /management/instances/$INSTANCE request.
 *
 * @param cls closure
 * @param igr response details
 */
typedef void
(*TALER_MERCHANT_GetManagementInstanceCallback)(
  TALER_MERCHANT_GET_MANAGEMENT_INSTANCE_RESULT_CLOSURE *cls,
  const struct TALER_MERCHANT_GetManagementInstanceResponse *igr);


/**
 * Start GET /management/instances/$INSTANCE operation.
 *
 * @param[in,out] gmi 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_instance_start (
  struct TALER_MERCHANT_GetManagementInstanceHandle *gmi,
  TALER_MERCHANT_GetManagementInstanceCallback cb,
  TALER_MERCHANT_GET_MANAGEMENT_INSTANCE_RESULT_CLOSURE *cb_cls);


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


#endif /* _TALER_MERCHANT__GET_MANAGEMENT_INSTANCES_INSTANCE_H */
