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

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


/**
 * Return KYC attribute information.
 *
 * @param cls closure
 * @param row_id current row in kyc_attributes table
 * @param h_payto account the attributes are about
 * @param provider_name name of the provider that collected the attributes
 * @param collection_time when were the attributes collected
 * @param expiration_time when does the data expire
 * @param properties properties that were set for @a h_payto
 * @param enc_attributes_size size of @a enc_attributes
 * @param enc_attributes the encrypted collected attributes
 * @return true to continue to iterate
 */
#ifndef TALER_EXCHANGEDB_ALL_ATTRIBUTES_RESULT_CLOSURE
/**
 * Type of the closure for #TALER_EXCHANGEDB_AllAttributesCallback.
 */
#define TALER_EXCHANGEDB_ALL_ATTRIBUTES_RESULT_CLOSURE void
#endif
typedef bool
(*TALER_EXCHANGEDB_AllAttributesCallback)(
  TALER_EXCHANGEDB_ALL_ATTRIBUTES_RESULT_CLOSURE *cls,
  uint64_t row_id,
  const struct TALER_NormalizedPaytoHashP *h_payto,
  const char *provider_name,
  struct GNUNET_TIME_Timestamp collection_time,
  struct GNUNET_TIME_Timestamp expiration_time,
  const json_t *properties,
  size_t enc_attributes_size,
  const void *enc_attributes);


/* Callback typedefs */
/**
 * Return KYC attribute information.
 *
 * @param cls closure
 * @param row_id current row in kyc_attributes table
 * @param h_payto account the attributes are about
 * @param provider_name name of the provider that collected the attributes
 * @param collection_time when were the attributes collected
 * @param expiration_time when does the data expire
 * @param properties properties that were set for @a h_payto
 * @param enc_attributes_size size of @a enc_attributes
 * @param enc_attributes the encrypted collected attributes
 * @return true to continue to iterate
 */
typedef bool
(*TALER_EXCHANGEDB_AllAttributesCallback)(
  TALER_EXCHANGEDB_ALL_ATTRIBUTES_RESULT_CLOSURE *cls,
  uint64_t row_id,
  const struct TALER_NormalizedPaytoHashP *h_payto,
  const char *provider_name,
  struct GNUNET_TIME_Timestamp collection_time,
  struct GNUNET_TIME_Timestamp expiration_time,
  const json_t *properties,
  size_t enc_attributes_size,
  const void *enc_attributes);

/**
 * Lookup all KYC attributes above @a min_row_id.
 *
 * @param pg the database context
 * @param min_row_id minimum row ID to return (exclusive)
 * @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_all_kyc_attributes (struct
                                             TALER_EXCHANGEDB_PostgresContext *
                                             pg
                                             ,
                                             uint64_t min_row_id,
                                             TALER_EXCHANGEDB_AllAttributesCallback
                                             cb,
                                             TALER_EXCHANGEDB_ALL_ATTRIBUTES_RESULT_CLOSURE
                                             *cb_cls);

#endif
