/*
  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-private-webhooks-WEBHOOK_ID.h
 * @brief C interface for GET /private/webhooks/$WEBHOOK_ID of the merchant backend
 * @author Priscilla Huang
 * @author Christian Grothoff
 */
#ifndef _TALER_MERCHANT__GET_PRIVATE_WEBHOOKS_WEBHOOK_ID_H
#define _TALER_MERCHANT__GET_PRIVATE_WEBHOOKS_WEBHOOK_ID_H

#include <taler/merchant/common.h>


/**
 * Handle for a GET /private/webhooks/$WEBHOOK_ID request.
 */
struct TALER_MERCHANT_GetPrivateWebhookHandle;


/**
 * Response details for a GET /private/webhooks/$WEBHOOK_ID request.
 */
struct TALER_MERCHANT_GetPrivateWebhookResponse
{

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

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

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

      /**
       * Event type that triggers this webhook.
       */
      const char *event_type;

      /**
       * URL to send the webhook notification to.
       */
      const char *url;

      /**
       * HTTP method to use.
       */
      const char *http_method;

      /**
       * Template for HTTP headers, or NULL.
       */
      const char *header_template;

      /**
       * Template for the HTTP body, or NULL.
       */
      const char *body_template;

    } ok;

  } details;

};


/**
 * Set up GET /private/webhooks/$WEBHOOK_ID 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 webhook_id identifier of the webhook to retrieve
 * @return handle to operation
 */
struct TALER_MERCHANT_GetPrivateWebhookHandle *
TALER_MERCHANT_get_private_webhook_create (
  struct GNUNET_CURL_Context *ctx,
  const char *url,
  const char *webhook_id);


#ifndef TALER_MERCHANT_GET_PRIVATE_WEBHOOK_RESULT_CLOSURE
/**
 * Type of the closure used by
 * the #TALER_MERCHANT_GetPrivateWebhookCallback.
 */
#define TALER_MERCHANT_GET_PRIVATE_WEBHOOK_RESULT_CLOSURE void
#endif /* TALER_MERCHANT_GET_PRIVATE_WEBHOOK_RESULT_CLOSURE */

/**
 * Callback for a GET /private/webhooks/$WEBHOOK_ID request.
 *
 * @param cls closure
 * @param wgr response details
 */
typedef void
(*TALER_MERCHANT_GetPrivateWebhookCallback)(
  TALER_MERCHANT_GET_PRIVATE_WEBHOOK_RESULT_CLOSURE *cls,
  const struct TALER_MERCHANT_GetPrivateWebhookResponse *wgr);


/**
 * Start GET /private/webhooks/$WEBHOOK_ID operation.
 *
 * @param[in,out] gpw 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_private_webhook_start (
  struct TALER_MERCHANT_GetPrivateWebhookHandle *gpw,
  TALER_MERCHANT_GetPrivateWebhookCallback cb,
  TALER_MERCHANT_GET_PRIVATE_WEBHOOK_RESULT_CLOSURE *cb_cls);


/**
 * Cancel GET /private/webhooks/$WEBHOOK_ID operation.  This function
 * must not be called by clients after the
 * TALER_MERCHANT_GetPrivateWebhookCallback has been invoked
 * (as in those cases it'll be called internally by the
 * implementation already).
 *
 * @param[in] gpw operation to cancel
 */
void
TALER_MERCHANT_get_private_webhook_cancel (
  struct TALER_MERCHANT_GetPrivateWebhookHandle *gpw);


#endif /* _TALER_MERCHANT__GET_PRIVATE_WEBHOOKS_WEBHOOK_ID_H */
