/*
   This file is part of TALER
   Copyright (C) 2026 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_exchanges.h
 * @brief implementation of the iterate_exchanges function for Postgres
 * @author Christian Grothoff
 */
#ifndef MERCHANT_DATABASE_ITERATE_EXCHANGES_H
#define MERCHANT_DATABASE_ITERATE_EXCHANGES_H

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


/**
 * Function called about the ``/keys`` status of every exchange
 * we are working with.
 *
 * @param cls closure
 * @param exchange_url base URL of the exchange
 * @param keys keys of the exchange, NULL if we do not have any yet
 * @param next_download when will be the next download
 * @param keys_expiration when does the current ``/keys`` response expire
 * @param http_status last HTTP status from ``/keys``
 * @param ec last error code from fetching ``/keys``
 */
typedef void
(*TALER_MERCHANTDB_ExchangesCallback)(
  void *cls,
  const char *exchange_url,
  const json_t *keys,
  struct GNUNET_TIME_Absolute next_download,
  struct GNUNET_TIME_Absolute keys_expiration,
  unsigned int http_status,
  enum TALER_ErrorCode ec);


/**
 * Call @a cb on each exchange we have in the database.
 *
 * @param pg database context
 * @param cb callback to invoke
 * @param cb_cls closure for @a cb
 * @return transaction status code
 */
enum GNUNET_DB_QueryStatus
TALER_MERCHANTDB_iterate_exchanges (
  struct TALER_MERCHANTDB_PostgresContext *pg,
  TALER_MERCHANTDB_ExchangesCallback cb,
  void *cb_cls);


#endif
