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

#include <taler/taler_util.h>
#include <taler/taler_json_lib.h>
#include "merchantdb_lib.h"


struct TALER_MERCHANTDB_PostgresContext;
/* Callback typedefs */
/**
 * Function called from ``iterate_kyc_statuses``
 * with KYC status information for this merchant.
 *
 * @param cls closure
 * @param h_wire hash of the wire account
 * @param payto_uri payto:// URI of the merchant's bank account
 * @param exchange_url base URL of the exchange for which this is a status
 * @param last_check when did we last get an update on our KYC status from the exchange
 * @param kyc_ok true if we satisfied the KYC requirements
 * @param access_token access token for the KYC SPA, NULL if we cannot access it yet (need KYC auth wire transfer)
 * @param last_http_status last HTTP status from /kyc-check
 * @param last_ec last Taler error code from /kyc-check
 * @param in_aml_review true if the account is pending review
 * @param jlimits JSON array of applicable AccountLimits, or NULL if unknown (like defaults apply)
 */
typedef void
(*TALER_MERCHANTDB_KycCallback)(
  void *cls,
  const struct TALER_MerchantWireHashP *h_wire,
  struct TALER_FullPayto payto_uri,
  const char *exchange_url,
  struct GNUNET_TIME_Timestamp last_check,
  bool kyc_ok,
  const struct TALER_AccountAccessTokenP *access_token,
  unsigned int last_http_status,
  enum TALER_ErrorCode last_ec,
  bool in_aml_review,
  const json_t *jlimits);

/**
 * Check an instance's account's KYC status. Triggers
 * a request to taler-merchant-kyccheck to get a
 * KYC status update as a side-effect!
 *
 * @param pg database context
 * @param merchant_id merchant backend instance ID
 * @param h_wire hash of the wire account to check,
 *        NULL to check all accounts of the merchant
 * @param exchange_url base URL of the exchange to check,
 *        NULL to check all exchanges
 * @param kyc_cb KYC status callback to invoke
 * @param kyc_cb_cls closure for @a kyc_cb
 * @return database result code
 */
enum GNUNET_DB_QueryStatus
TALER_MERCHANTDB_iterate_kyc_statuses (struct TALER_MERCHANTDB_PostgresContext *pg,
                                       const char *merchant_id,
                                       const struct TALER_MerchantWireHashP *h_wire,
                                       const char *exchange_url,
                                       TALER_MERCHANTDB_KycCallback kyc_cb,
                                       void *kyc_cb_cls);

#endif
