/*
   This file is part of TALER
   Copyright (C) 2023 Taler Systems SA

   TALER is free software; you can redistribute it and/or modify it under the
   terms of the GNU 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 General Public License for more details.

   You should have received a copy of the GNU General Public License along with
   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
 */
/**
 * @file src/include/merchant-database/iterate_webhooks_by_event.h
 * @brief implementation of the iterate_webhooks_by_event function for Postgres
 * @author Iván Ávalos
 */
#ifndef MERCHANT_DATABASE_ITERATE_WEBHOOKS_BY_EVENT_H
#define MERCHANT_DATABASE_ITERATE_WEBHOOKS_BY_EVENT_H

#include <taler/taler_util.h>
#include <taler/taler_json_lib.h>
#include "merchantdb_lib.h"


/**
 * Typically called by `iterate_webhooks_by_event`.
 *
 * @param cls a `json_t *` JSON array to build
 * @param webhook_serial reference to the configured webhook template.
 * @param event_type which type of event triggers this type of webhook
 * @param url the HTTP URL to make the webhook request to
 * @param http_method HTTP method use for the webhook
 * @param header_template template for the header of the webhook
 * @param body_template template for the body of the webhook
 */
typedef void
(*TALER_MERCHANTDB_WebhookDetailCallback)(
  void *cls,
  uint64_t webhook_serial,
  const char *event_type,
  const char *url,
  const char *http_method,
  const char *header_template,
  const char *body_template);

/**
   * Lookup webhook by event
   *
   * @param pg database context
   * @param instance_id instance to lookup webhook for
   * @param event_type event that we need to put in the pending webhook
   * @param[out] cb set to the webhook details on success
   * @param cb_cls callback closure
   * @return database result code
   */
enum GNUNET_DB_QueryStatus
TALER_MERCHANTDB_iterate_webhooks_by_event (
  struct TALER_MERCHANTDB_PostgresContext *pg,
  const char *instance_id,
  const char *event_type,
  TALER_MERCHANTDB_WebhookDetailCallback cb,
  void *cb_cls);

#endif
