/*
  This file is part of TALER
  Copyright (C) 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-seed.h
 * @brief C interface for GET /seed
 * @author Christian Grothoff
 */
#ifndef _TALER_EXCHANGE__GET_SEED_H
#define _TALER_EXCHANGE__GET_SEED_H

#include <taler/exchange/common.h>

/**
 * Handle for an operation to GET /seed.
 */
struct TALER_EXCHANGE_GetSeedHandle;


/**
 * Response from a GET /seed request.
 * The response body is raw binary entropy, not JSON.
 * Wallets MUST mix the returned value with locally generated entropy.
 */
struct TALER_EXCHANGE_GetSeedResponse
{
  /**
   * HTTP response data.
   */
  struct TALER_EXCHANGE_HttpResponse hr;

  /**
   * Response details depending on HTTP status.
   */
  union
  {
    /**
     * Details if HTTP status is #MHD_HTTP_OK.
     */
    struct
    {
      /**
       * High-entropy seed data returned by the exchange.
       * Must be mixed with locally generated entropy.
       * Only valid while the callback is executing.
       */
      const void *seed;

      /**
       * Number of bytes in @e seed.
       */
      size_t seed_size;

    } ok;
  } details;

};


#ifndef TALER_EXCHANGE_GET_SEED_RESULT_CLOSURE
/**
 * Type of the closure used by
 * the #TALER_EXCHANGE_GetSeedCallback.
 */
#define TALER_EXCHANGE_GET_SEED_RESULT_CLOSURE void
#endif /* TALER_EXCHANGE_GET_SEED_RESULT_CLOSURE */

/**
 * Type of the function that receives the result of a
 * GET /seed request.
 *
 * @param cls closure
 * @param result result returned by the HTTP server
 */
typedef void
(*TALER_EXCHANGE_GetSeedCallback)(
  TALER_EXCHANGE_GET_SEED_RESULT_CLOSURE *cls,
  const struct TALER_EXCHANGE_GetSeedResponse *result);


/**
 * Set up GET /seed 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_GetSeedHandle *
TALER_EXCHANGE_get_seed_create (
  struct GNUNET_CURL_Context *ctx,
  const char *url);


/**
 * Start GET /seed operation.
 *
 * @param[in,out] gsh 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_seed_start (
  struct TALER_EXCHANGE_GetSeedHandle *gsh,
  TALER_EXCHANGE_GetSeedCallback cb,
  TALER_EXCHANGE_GET_SEED_RESULT_CLOSURE *cb_cls);


/**
 * Cancel GET /seed operation.  This function must not be called
 * by clients after the TALER_EXCHANGE_GetSeedCallback has been invoked
 * (as in those cases it'll be called internally by the
 * implementation already).
 *
 * @param[in] gsh operation to cancel
 */
void
TALER_EXCHANGE_get_seed_cancel (
  struct TALER_EXCHANGE_GetSeedHandle *gsh);


#endif /* _TALER_EXCHANGE__GET_SEED_H */
