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

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


/**
 * Return account summary information.
 *
 * @param cls closure
 * @param row_id current row in AML status table
 * @param h_payto account for which the attribute data is stored
 * @param open_time when was the account opened formally,
 *          GNUNET_TIME_UNIT_FOREVER_TS if it was never opened
 * @param close_time when was the account formally closed,
 *          GNUNET_TIME_UNIT_ZERO_TS if it was never closed
 * @param comments comments on the account
 * @param high_risk is this a high-risk business relationship
 * @param to_investigate TRUE if this account should be investigated
 * @param payto the payto URI of the account
 */
#ifndef TALER_EXCHANGEDB_AML_ACCOUNT_LIST_RESULT_CLOSURE
/**
 * Type of the closure for #TALER_EXCHANGEDB_AmlAccountListCallback.
 */
#define TALER_EXCHANGEDB_AML_ACCOUNT_LIST_RESULT_CLOSURE void
#endif
typedef void
(*TALER_EXCHANGEDB_AmlAccountListCallback)(
  TALER_EXCHANGEDB_AML_ACCOUNT_LIST_RESULT_CLOSURE *cls,
  uint64_t row_id,
  const struct TALER_NormalizedPaytoHashP *h_payto,
  struct GNUNET_TIME_Timestamp open_time,
  struct GNUNET_TIME_Timestamp close_time,
  const char *comments,
  bool high_risk,
  bool to_investigate,
  struct TALER_FullPayto payto);


/* Callback typedefs */
/**
 * Return account summary information.
 *
 * @param cls closure
 * @param row_id current row in AML status table
 * @param h_payto account for which the attribute data is stored
 * @param open_time when was the account opened formally,
 *          GNUNET_TIME_UNIT_FOREVER_TS if it was never opened
 * @param close_time when was the account formally closed,
 *          GNUNET_TIME_UNIT_ZERO_TS if it was never closed
 * @param comments comments on the account
 * @param high_risk is this a high-risk business relationship
 * @param to_investigate TRUE if this account should be investigated
 * @param payto the payto URI of the account
 */
typedef void
(*TALER_EXCHANGEDB_AmlAccountListCallback)(
  TALER_EXCHANGEDB_AML_ACCOUNT_LIST_RESULT_CLOSURE *cls,
  uint64_t row_id,
  const struct TALER_NormalizedPaytoHashP *h_payto,
  struct GNUNET_TIME_Timestamp open_time,
  struct GNUNET_TIME_Timestamp close_time,
  const char *comments,
  bool high_risk,
  bool to_investigate,
  struct TALER_FullPayto payto);

/**
 * List accounts managed by the exchange (for AML/KYC).
 *
 * @param pg the database context
 * @param investigation_only filter by investigation state
 * @param open_only filter for only open accounts
 * @param high_risk_only filter for only high-risk accounts
 * @param offset row to start from
 * @param limit how many records to return (negative
 *        to go back in time, positive to go forward)
 * @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_kyc_accounts (struct TALER_EXCHANGEDB_PostgresContext *
                                       pg,
                                       enum TALER_EXCHANGE_YesNoAll
                                       investigation_only,
                                       enum TALER_EXCHANGE_YesNoAll open_only,
                                       enum TALER_EXCHANGE_YesNoAll
                                       high_risk_only,
                                       uint64_t offset,
                                       int64_t limit,
                                       TALER_EXCHANGEDB_AmlAccountListCallback
                                       cb
                                       ,
                                       TALER_EXCHANGEDB_AML_ACCOUNT_LIST_RESULT_CLOSURE
                                       *cb_cls);


#endif
