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

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


/**
 * Function called with historic KYC events of an
 * account.
 *
 * @param cls closure
 * @param provider_name name of the KYC provider
 * @param finished did the KYC process finish
 * @param error_code error code from the KYC process
 * @param error_message error message from the KYC process,
 *    or NULL for none
 * @param provider_user_id user ID at the provider
 *    or NULL for none
 * @param provider_legitimization_id legitimization process ID at the provider
 *    or NULL for none
 * @param collection_time when was the data collected
 * @param expiration_time when does the collected data expire
 * @param encrypted_attributes_len number of bytes in @a encrypted_attributes
 * @param encrypted_attributes encrypted KYC attributes
 */
#ifndef TALER_EXCHANGEDB_KYC_HISTORY_RESULT_CLOSURE
/**
 * Type of the closure for #TALER_EXCHANGEDB_KycHistoryCallback.
 */
#define TALER_EXCHANGEDB_KYC_HISTORY_RESULT_CLOSURE void
#endif
typedef void
(*TALER_EXCHANGEDB_KycHistoryCallback) (
  TALER_EXCHANGEDB_KYC_HISTORY_RESULT_CLOSURE *cls,
  const char *provider_name,
  bool finished,
  enum TALER_ErrorCode error_code,
  const char *error_message,
  const char *provider_user_id,
  const char *provider_legitimization_id,
  struct GNUNET_TIME_Timestamp collection_time,
  struct GNUNET_TIME_Absolute expiration_time,
  size_t encrypted_attributes_len,
  const void *encrypted_attributes);


/* Callback typedefs */
/**
 * Function called with historic KYC events of an
 * account.
 *
 * @param cls closure
 * @param provider_name name of the KYC provider
 * @param finished did the KYC process finish
 * @param error_code error code from the KYC process
 * @param error_message error message from the KYC process,
 *    or NULL for none
 * @param provider_user_id user ID at the provider
 *    or NULL for none
 * @param provider_legitimization_id legitimization process ID at the provider
 *    or NULL for none
 * @param collection_time when was the data collected
 * @param expiration_time when does the collected data expire
 * @param encrypted_attributes_len number of bytes in @a encrypted_attributes
 * @param encrypted_attributes encrypted KYC attributes
 */
typedef void
(*TALER_EXCHANGEDB_KycHistoryCallback) (
  TALER_EXCHANGEDB_KYC_HISTORY_RESULT_CLOSURE *cls,
  const char *provider_name,
  bool finished,
  enum TALER_ErrorCode error_code,
  const char *error_message,
  const char *provider_user_id,
  const char *provider_legitimization_id,
  struct GNUNET_TIME_Timestamp collection_time,
  struct GNUNET_TIME_Absolute expiration_time,
  size_t encrypted_attributes_len,
  const void *encrypted_attributes);

/**
 * Lookup KYC 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 cb function to call on results
 * @param cb_cls closure for @a cb
 * @return database transaction status
 */
enum GNUNET_DB_QueryStatus
TALER_EXCHANGEDB_iterate_kyc_history (struct TALER_EXCHANGEDB_PostgresContext *
                                      pg
                                      ,
                                      const struct TALER_NormalizedPaytoHashP *
                                      h_payto,
                                      TALER_EXCHANGEDB_KycHistoryCallback cb,
                                      TALER_EXCHANGEDB_KYC_HISTORY_RESULT_CLOSURE
                                      *cb_cls);

#endif
