/*
   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/exchange-database/iterate_aml_measures.h
 * @brief implementation of the iterate_aml_measures function for Postgres
 * @author Christian Grothoff
 */
#ifndef EXCHANGE_DATABASE_ITERATE_AML_MEASURES_H
#define EXCHANGE_DATABASE_ITERATE_AML_MEASURES_H

#include "taler/taler_util.h"
#include "taler/taler_json_lib.h"
#include "exchangedb_lib.h"


/**
 * Function called with legitimization measures.
 *
 * @param cls closure
 * @param h_payto hash of account the measure applies to
 * @param start_time when was the process started
 * @param jmeasures object of type ``LegitimizationMeasures``
 * @param is_finished true if the measure was finished
 * @param measure_serial_id row ID of the measure in the exchange table
 */
#ifndef TALER_EXCHANGEDB_LEGITIMIZATION_MEASURE_RESULT_CLOSURE
/**
 * Type of the closure for #TALER_EXCHANGEDB_LegitimizationMeasureCallback.
 */
#define TALER_EXCHANGEDB_LEGITIMIZATION_MEASURE_RESULT_CLOSURE void
#endif
typedef void
(*TALER_EXCHANGEDB_LegitimizationMeasureCallback) (
  TALER_EXCHANGEDB_LEGITIMIZATION_MEASURE_RESULT_CLOSURE *cls,
  struct TALER_NormalizedPaytoHashP *h_payto,
  struct GNUNET_TIME_Absolute start_time,
  const json_t *jmeasures,
  bool is_finished,
  uint64_t measure_serial_id);


/* Callback typedefs */
/**
 * Function called with legitimization measures.
 *
 * @param cls closure
 * @param h_payto hash of account the measure applies to
 * @param start_time when was the process started
 * @param jmeasures object of type ``LegitimizationMeasures``
 * @param is_finished true if the measure was finished
 * @param measure_serial_id row ID of the measure in the exchange table
 */
typedef void
(*TALER_EXCHANGEDB_LegitimizationMeasureCallback) (
  TALER_EXCHANGEDB_LEGITIMIZATION_MEASURE_RESULT_CLOSURE *cls,
  struct TALER_NormalizedPaytoHashP *h_payto,
  struct GNUNET_TIME_Absolute start_time,
  const json_t *jmeasures,
  bool is_finished,
  uint64_t measure_serial_id);

/**
 * Lookup legitimization measures.
 *
 * @param pg the database context
 * @param h_payto account for which the attribute data is stored,
 *                NULL to select for all accounts
 * @param active_only select only measures that are active
 * @param offset row offset to select from
 * @param limit number of results to return, negative to
 *               return in descending order from @a offset
 * @param cb callback to invoke on each match
 * @param cb_cls closure for @a cb
 * @return database transaction status
 */
enum GNUNET_DB_QueryStatus
TALER_EXCHANGEDB_iterate_aml_measures (struct TALER_EXCHANGEDB_PostgresContext *
                                       pg,
                                       const struct TALER_NormalizedPaytoHashP *
                                       h_payto
                                       ,
                                       enum TALER_EXCHANGE_YesNoAll active_only,
                                       uint64_t offset,
                                       int64_t limit,
                                       TALER_EXCHANGEDB_LegitimizationMeasureCallback
                                       cb,
                                       TALER_EXCHANGEDB_LEGITIMIZATION_MEASURE_RESULT_CLOSURE
                                       *cb_cls);

#endif
