/*
  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 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-management-keys.h
 * @brief C interface for GET /management/keys
 * @author Christian Grothoff
 */
#ifndef _TALER_EXCHANGE__GET_MANAGEMENT_KEYS_H
#define _TALER_EXCHANGE__GET_MANAGEMENT_KEYS_H

#include <taler/exchange/common.h>

/**
 * Handle for an operation to GET /management/keys.
 */
struct TALER_EXCHANGE_GetManagementKeysHandle;


/**
 * @brief Future signing public key of the exchange.
 */
struct TALER_EXCHANGE_FutureSigningPublicKey
{
  /**
   * The signing public key.
   */
  struct TALER_ExchangePublicKeyP key;

  /**
   * Signature by the security module affirming it owns this key.
   */
  struct TALER_SecurityModuleSignatureP signkey_secmod_sig;

  /**
   * Validity start time.
   */
  struct GNUNET_TIME_Timestamp valid_from;

  /**
   * Validity expiration time (how long the exchange may use it).
   */
  struct GNUNET_TIME_Timestamp valid_until;

  /**
   * Validity expiration time for legal disputes.
   */
  struct GNUNET_TIME_Timestamp valid_legal;
};


/**
 * @brief Public information about a future denomination key of the exchange.
 */
struct TALER_EXCHANGE_FutureDenomPublicKey
{
  /**
   * The public key.
   */
  struct TALER_DenominationPublicKey key;

  /**
   * Signature by the security module affirming it owns this key.
   */
  struct TALER_SecurityModuleSignatureP denom_secmod_sig;

  /**
   * Timestamp indicating when the denomination key becomes valid.
   */
  struct GNUNET_TIME_Timestamp valid_from;

  /**
   * Timestamp indicating when the denomination key can no longer
   * be used for new withdrawals.
   */
  struct GNUNET_TIME_Timestamp withdraw_valid_until;

  /**
   * Timestamp indicating when coins of this denomination become invalid.
   */
  struct GNUNET_TIME_Timestamp expire_deposit;

  /**
   * When do signatures with this denomination key become invalid?
   * After this point these signatures cannot be used in legal disputes.
   */
  struct GNUNET_TIME_Timestamp expire_legal;

  /**
   * The value of this denomination.
   */
  struct TALER_Amount value;

  /**
   * The applicable fee for withdrawing a coin of this denomination.
   */
  struct TALER_Amount fee_withdraw;

  /**
   * The applicable fee to spend a coin of this denomination.
   */
  struct TALER_Amount fee_deposit;

  /**
   * The applicable fee to melt/refresh a coin of this denomination.
   */
  struct TALER_Amount fee_refresh;

  /**
   * The applicable fee to refund a coin of this denomination.
   */
  struct TALER_Amount fee_refund;

};


/**
 * @brief Information about future keys from the exchange.
 */
struct TALER_EXCHANGE_FutureKeys
{
  /**
   * Array of the exchange's future online signing keys.
   */
  struct TALER_EXCHANGE_FutureSigningPublicKey *sign_keys;

  /**
   * Array of the exchange's future denomination keys.
   */
  struct TALER_EXCHANGE_FutureDenomPublicKey *denom_keys;

  /**
   * Public key of the signkey security module.
   */
  struct TALER_SecurityModulePublicKeyP signkey_secmod_public_key;

  /**
   * Public key of the RSA denomination security module.
   */
  struct TALER_SecurityModulePublicKeyP denom_secmod_public_key;

  /**
   * Public key of the CS denomination security module.
   */
  struct TALER_SecurityModulePublicKeyP denom_secmod_cs_public_key;

  /**
   * Offline master public key used by this exchange.
   */
  struct TALER_MasterPublicKeyP master_pub;

  /**
   * Length of the @e sign_keys array.
   */
  unsigned int num_sign_keys;

  /**
   * Length of the @e denom_keys array.
   */
  unsigned int num_denom_keys;

};


/**
 * Response from a GET /management/keys request.
 */
struct TALER_EXCHANGE_GetManagementKeysResponse
{
  /**
   * HTTP response data.
   */
  struct TALER_EXCHANGE_HttpResponse hr;

  /**
   * Response details depending on the HTTP status.
   */
  union
  {
    /**
     * Details if HTTP status is #MHD_HTTP_OK.
     */
    struct
    {
      /**
       * Information about the various future keys used by the exchange.
       */
      struct TALER_EXCHANGE_FutureKeys keys;

    } ok;
  } details;

};

#ifndef TALER_EXCHANGE_GET_MANAGEMENT_KEYS_RESULT_CLOSURE
/**
 * Type of the closure used by
 * the #TALER_EXCHANGE_GetManagementKeysCallback.
 */
#define TALER_EXCHANGE_GET_MANAGEMENT_KEYS_RESULT_CLOSURE void
#endif /* TALER_EXCHANGE_GET_MANAGEMENT_KEYS_RESULT_CLOSURE */

/**
 * Type of the function that receives the result of a
 * GET /management/keys request.
 *
 * @param cls closure
 * @param result result returned by the HTTP server
 */
typedef void
(*TALER_EXCHANGE_GetManagementKeysCallback)(
  TALER_EXCHANGE_GET_MANAGEMENT_KEYS_RESULT_CLOSURE *cls,
  const struct TALER_EXCHANGE_GetManagementKeysResponse *result);


/**
 * Set up GET /management/keys 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_GetManagementKeysHandle *
TALER_EXCHANGE_get_management_keys_create (
  struct GNUNET_CURL_Context *ctx,
  const char *url);


/**
 * Start GET /management/keys operation.
 *
 * @param[in,out] gmkh 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_management_keys_start (
  struct TALER_EXCHANGE_GetManagementKeysHandle *gmkh,
  TALER_EXCHANGE_GetManagementKeysCallback cb,
  TALER_EXCHANGE_GET_MANAGEMENT_KEYS_RESULT_CLOSURE *cb_cls);


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


#endif /* _TALER_EXCHANGE__GET_MANAGEMENT_KEYS_H */
