/*
   This file is part of TALER
   Copyright (C) 2024 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_donau_instances.h
 * @brief implementation of the iterate_donau_instances function for Postgres
 * @author Bohdan Potuzhnyi
 * @author Vlada Svirsh
 */
#ifndef MERCHANT_DATABASE_ITERATE_DONAU_INSTANCES_H
#define MERCHANT_DATABASE_ITERATE_DONAU_INSTANCES_H

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


struct TALER_MERCHANTDB_PostgresContext;
/* Callback typedefs */
/**
 * Callback function typically used by `iterate_donau_instances` to handle
 * the details of each Donau instance retrieved from the database.
 *
 * @param cls Closure to pass additional context or data to the callback function.
 * @param donau_instance_serial Serial number of the Donau instance in the merchant database.
 * @param donau_url The URL of the Donau instance.
 * @param charity_name The name of the charity associated with the Donau instance.
 * @param charity_pub_key Pointer to the charity's public key used for cryptographic operations.
 * @param charity_id The unique identifier for the charity within the Donau instance.
 * @param charity_max_per_year Maximum allowed donations to the charity for the current year.
 * @param charity_receipts_to_date Total donations received by the charity so far in the current year.
 * @param current_year The year for which the donation data is being tracked.
 * @param donau_keys_json JSON object containing additional key-related information for the Donau instance, NULL if not (yet) available.
 */
typedef void
(*TALER_MERCHANTDB_DonauInstanceCallback)(
  void *cls,
  uint64_t donau_instance_serial,
  const char *donau_url,
  const char *charity_name,
  const struct DONAU_CharityPublicKeyP *charity_pub_key,
  uint64_t charity_id,
  const struct TALER_Amount *charity_max_per_year,
  const struct TALER_Amount *charity_receipts_to_date,
  int64_t current_year,
  const json_t *donau_keys_json
  );

/**
 * Select Donau instances from the database.
 *
 * @param pg database context
 * @param id the ID of the merchant instance, NULL for all instances
 * @param cb callback function to call with each result
 * @param cb_cls closure for the callback
 * @return status of the PG
 */
enum GNUNET_DB_QueryStatus
TALER_MERCHANTDB_iterate_donau_instances (struct TALER_MERCHANTDB_PostgresContext *pg,
                                          const char *id,
                                          TALER_MERCHANTDB_DonauInstanceCallback cb,
                                          void *cb_cls);

#endif
