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

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


/**
 * Closure for various history building functions.
 */
struct TALER_EXCHANGEDB_HistoryBuilderContext
{
  /**
   * Account to build history for.
   */
  const struct TALER_NormalizedPaytoHashP *account;

  /**
   * Database context to build history with.
   */
  struct TALER_EXCHANGEDB_PostgresContext *pg;

  /**
   * Key to use to decrypt KYC attributes.
   */
  struct TALER_AttributeEncryptionKeyP *attribute_key;

  /**
   * True if @e account is for a wallet.
   */
  bool is_wallet;
};


/**
 * Function called to obtain an AML
 * history in JSON on-demand if needed.
 *
 * @param cls must be a `struct TALER_EXCHANGEDB_HistoryBuilderContext *`
 * @return AML history in JSON format, NULL on error
 */
json_t *
TALER_EXCHANGEDB_aml_history_builder (void *cls);


/**
 * Function called to obtain a KYC
 * history in JSON on-demand if needed.
 *
 * @param cls must be a `struct TALER_EXCHANGEDB_HistoryBuilderContext *`
 * @return KYC history in JSON format, NULL on error
 */
json_t *
TALER_EXCHANGEDB_kyc_history_builder (void *cls);


/**
 * Function called to obtain the current ``LegitimizationRuleSet``
 * in JSON for an account on-demand if needed.
 *
 * @param cls must be a `struct TALER_EXCHANGEDB_HistoryBuilderContext *`
 * @return KYC history in JSON format, NULL on error
 */
json_t *
TALER_EXCHANGEDB_current_rule_builder (void *cls);


/**
 * Function called to obtain the latest KYC attributes
 * in JSON for an account on-demand if needed.
 *
 * @param cls must be a `struct TALER_EXCHANGEDB_HistoryBuilderContext *`
 * @return KYC attributes in JSON format, NULL on error
 */
json_t *
TALER_EXCHANGEDB_current_attributes_builder (void *cls);


#endif
