/*
  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 include/taler/taler-merchant/get-private-webhooks.h
 * @brief C interface for GET /private/webhooks of the merchant backend
 * @author Christian Grothoff
 */
#ifndef _TALER_MERCHANT__GET_PRIVATE_WEBHOOKS_H
#define _TALER_MERCHANT__GET_PRIVATE_WEBHOOKS_H

#include <taler/taler-merchant/common.h>


/**
 * Handle for a GET /private/webhooks request.
 */
struct TALER_MERCHANT_WebhooksGetHandle;


/**
 * Entry for one webhook.
 */
struct TALER_MERCHANT_WebhookEntry
{

  /**
   * Identifier of the webhook.
   */
  const char *webhook_id;

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

};


/**
 * Response details for a GET /private/webhooks request.
 */
struct TALER_MERCHANT_WebhooksGetResponse
{

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

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

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

      /**
       * Number of webhooks in @a webhooks.
       */
      unsigned int webhooks_length;

      /**
       * Array of webhook entries.
       */
      const struct TALER_MERCHANT_WebhookEntry *webhooks;

    } ok;

  } details;

};


/**
 * Callback for a GET /private/webhooks request.
 *
 * @param cls closure
 * @param wgr response details
 */
typedef void
(*TALER_MERCHANT_WebhooksGetCallback)(
  void *cls,
  const struct TALER_MERCHANT_WebhooksGetResponse *wgr);


/**
 * Issue a GET /private/webhooks request.
 *
 * @param ctx CURL context to use
 * @param backend_url base URL of the merchant backend
 * @param cb callback to invoke with the result
 * @param cb_cls closure for @a cb
 * @return handle for the request, NULL on hard error
 */
struct TALER_MERCHANT_WebhooksGetHandle *
TALER_MERCHANT_webhooks_get (struct GNUNET_CURL_Context *ctx,
                             const char *backend_url,
                             TALER_MERCHANT_WebhooksGetCallback cb,
                             void *cb_cls);


/**
 * Cancel a GET /private/webhooks request.
 *
 * @param[in] wgh handle to cancel
 */
void
TALER_MERCHANT_webhooks_get_cancel (
  struct TALER_MERCHANT_WebhooksGetHandle *wgh);


#endif
