/*
  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-contracts-CONTRACT_PUB.h
 * @brief C interface for GET /contracts/$CONTRACT_PUB
 * @author Christian Grothoff
 */
#ifndef _TALER_EXCHANGE__GET_CONTRACTS_CONTRACT_PUB_H
#define _TALER_EXCHANGE__GET_CONTRACTS_CONTRACT_PUB_H

#include <taler/exchange/common.h>

/**
 * Handle for an operation to GET /contracts/$CONTRACT_PUB.
 */
struct TALER_EXCHANGE_GetContractsHandle;


/**
 * Response from a GET /contracts/$CONTRACT_PUB request.
 */
struct TALER_EXCHANGE_GetContractsResponse
{
  /**
   * HTTP response data.
   */
  struct TALER_EXCHANGE_HttpResponse hr;

  /**
   * Details depending on the HTTP status code.
   */
  union
  {
    /**
     * Information returned on #MHD_HTTP_OK.
     */
    struct
    {
      /**
       * Public key of the purse.
       */
      struct TALER_PurseContractPublicKeyP purse_pub;

      /**
       * Encrypted contract data.
       */
      const void *econtract;

      /**
       * Number of bytes in @e econtract.
       */
      size_t econtract_size;

    } ok;

  } details;

};


#ifndef TALER_EXCHANGE_GET_CONTRACTS_RESULT_CLOSURE
/**
 * Type of the closure used by
 * the #TALER_EXCHANGE_GetContractsCallback.
 */
#define TALER_EXCHANGE_GET_CONTRACTS_RESULT_CLOSURE void
#endif /* TALER_EXCHANGE_GET_CONTRACTS_RESULT_CLOSURE */

/**
 * Type of the function that receives the result of a
 * GET /contracts/$CONTRACT_PUB request.
 *
 * @param cls closure
 * @param result result returned by the HTTP server
 */
typedef void
(*TALER_EXCHANGE_GetContractsCallback)(
  TALER_EXCHANGE_GET_CONTRACTS_RESULT_CLOSURE *cls,
  const struct TALER_EXCHANGE_GetContractsResponse *result);


/**
 * Set up GET /contracts/$CONTRACT_PUB operation.
 * Note that you must explicitly start the operation after setup.
 *
 * @param ctx the context
 * @param url base URL of the exchange
 * @param contract_priv private key of the contract
 * @return handle to operation
 */
struct TALER_EXCHANGE_GetContractsHandle *
TALER_EXCHANGE_get_contracts_create (
  struct GNUNET_CURL_Context *ctx,
  const char *url,
  const struct TALER_ContractDiffiePrivateP *contract_priv);


/**
 * Start GET /contracts/$CONTRACT_PUB operation.
 *
 * @param[in,out] gch 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_contracts_start (
  struct TALER_EXCHANGE_GetContractsHandle *gch,
  TALER_EXCHANGE_GetContractsCallback cb,
  TALER_EXCHANGE_GET_CONTRACTS_RESULT_CLOSURE *cb_cls);


/**
 * Cancel GET /contracts/$CONTRACT_PUB operation.  This function must not
 * be called by clients after the TALER_EXCHANGE_GetContractsCallback has
 * been invoked (as in those cases it'll be called internally by the
 * implementation already).
 *
 * @param[in] gch operation to cancel
 */
void
TALER_EXCHANGE_get_contracts_cancel (
  struct TALER_EXCHANGE_GetContractsHandle *gch);


#endif /* _TALER_EXCHANGE__GET_CONTRACTS_CONTRACT_PUB_H */
