/*
   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_history.h
 * @brief implementation of the iterate_aml_history function for Postgres
 * @author Christian Grothoff
 */
#ifndef EXCHANGE_DATABASE_ITERATE_AML_HISTORY_H
#define EXCHANGE_DATABASE_ITERATE_AML_HISTORY_H

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


/**
 * Function called with historic AML events of an
 * account.
 *
 * @param cls closure
 * @param outcome_serial_id row ID of the decision
 * @param decision_time when was the decision taken
 * @param justification what was the given justification
 * @param decider_pub which key signed the decision
 * @param jproperties what are the new account properties
 * @param jnew_rules what are the new account rules
 * @param to_investigate should AML staff investigate
 *          after the decision
 * @param is_active is this the active decision
 */
#ifndef TALER_EXCHANGEDB_AML_HISTORY_RESULT_CLOSURE
/**
 * Type of the closure for #TALER_EXCHANGEDB_AmlHistoryCallback.
 */
#define TALER_EXCHANGEDB_AML_HISTORY_RESULT_CLOSURE void
#endif
typedef void
(*TALER_EXCHANGEDB_AmlHistoryCallback) (
  TALER_EXCHANGEDB_AML_HISTORY_RESULT_CLOSURE *cls,
  uint64_t outcome_serial_id,
  struct GNUNET_TIME_Timestamp decision_time,
  const char *justification,
  const struct TALER_AmlOfficerPublicKeyP *decider_pub,
  const json_t *jproperties,
  const json_t *jnew_rules,
  bool to_investigate,
  bool is_active);


/* Callback typedefs */
/**
 * Function called with historic AML events of an
 * account.
 *
 * @param cls closure
 * @param outcome_serial_id row ID of the decision
 * @param decision_time when was the decision taken
 * @param justification what was the given justification
 * @param decider_pub which key signed the decision
 * @param jproperties what are the new account properties
 * @param jnew_rules what are the new account rules
 * @param to_investigate should AML staff investigate
 *          after the decision
 * @param is_active is this the active decision
 */
typedef void
(*TALER_EXCHANGEDB_AmlHistoryCallback) (
  TALER_EXCHANGEDB_AML_HISTORY_RESULT_CLOSURE *cls,
  uint64_t outcome_serial_id,
  struct GNUNET_TIME_Timestamp decision_time,
  const char *justification,
  const struct TALER_AmlOfficerPublicKeyP *decider_pub,
  const json_t *jproperties,
  const json_t *jnew_rules,
  bool to_investigate,
  bool is_active);

/**
 * Lookup AML history for an account identified via
 * @a h_payto.
 *
 * @param pg the database context
 * @param h_payto hash of account to lookup history for
 * @param offset row ID to start returning results from
 * @param limit how many results to return, negative for descending order
 * @param cb function to call on results
 * @param cb_cls closure for @a cb
 * @return database transaction status
 */
enum GNUNET_DB_QueryStatus
TALER_EXCHANGEDB_iterate_aml_history (struct TALER_EXCHANGEDB_PostgresContext *
                                      pg
                                      ,
                                      const struct TALER_NormalizedPaytoHashP *
                                      h_payto,
                                      uint64_t offset,
                                      int64_t limit,
                                      TALER_EXCHANGEDB_AmlHistoryCallback cb,
                                      TALER_EXCHANGEDB_AML_HISTORY_RESULT_CLOSURE
                                      *cb_cls);


#endif
