/*
   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 src/include/exchange-database/iterate_wire_accounts.h
 * @brief implementation of the iterate_wire_accounts function for Postgres
 * @author Christian Grothoff
 */
#ifndef EXCHANGE_DATABASE_ITERATE_WIRE_ACCOUNTS_H
#define EXCHANGE_DATABASE_ITERATE_WIRE_ACCOUNTS_H

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


/**
 * Provide information about a wire account.
 *
 * @param cls closure
 * @param payto_uri the exchange bank account URI
 * @param conversion_url URL of a conversion service, NULL if there is no conversion
 * @param open_banking_gateway open banking gateway service, NULL if unavailable
 * @param prepared_transfer_url prepared transfer service, NULL if unavailable
 * @param debit_restrictions JSON array with debit restrictions on the account
 * @param credit_restrictions JSON array with credit restrictions on the account
 * @param master_sig master key signature affirming that this is a bank
 *                   account of the exchange (of purpose #TALER_SIGNATURE_MASTER_WIRE_DETAILS)
 * @param bank_label label the wallet should use to display the account, can be NULL
 * @param priority priority for ordering bank account labels
 */
#ifndef TALER_EXCHANGEDB_WIRE_ACCOUNT_RESULT_CLOSURE
/**
 * Type of the closure for #TALER_EXCHANGEDB_WireAccountCallback.
 */
#define TALER_EXCHANGEDB_WIRE_ACCOUNT_RESULT_CLOSURE void
#endif
typedef void
(*TALER_EXCHANGEDB_WireAccountCallback)(
  TALER_EXCHANGEDB_WIRE_ACCOUNT_RESULT_CLOSURE *cls,
  const struct TALER_FullPayto payto_uri,
  const char *conversion_url,
  const char *open_banking_gateway,
  const char *prepared_transfer_url,
  const json_t *debit_restrictions,
  const json_t *credit_restrictions,
  const struct TALER_MasterSignatureP *master_sig,
  const char *bank_label,
  int64_t priority);


/* Callback typedefs */
/**
 * Provide information about a wire account.
 *
 * @param cls closure
 * @param payto_uri the exchange bank account URI
 * @param conversion_url URL of a conversion service, NULL if there is no conversion
 * @param open_banking_gateway open banking gateway service, NULL if unavailable
 * @param prepared_transfer_url prepared transfer service, NULL if unavailable
 * @param debit_restrictions JSON array with debit restrictions on the account
 * @param credit_restrictions JSON array with credit restrictions on the account
 * @param master_sig master key signature affirming that this is a bank
 *                   account of the exchange (of purpose #TALER_SIGNATURE_MASTER_WIRE_DETAILS)
 * @param bank_label label the wallet should use to display the account, can be NULL
 * @param priority priority for ordering bank account labels
 */
typedef void
(*TALER_EXCHANGEDB_WireAccountCallback)(
  TALER_EXCHANGEDB_WIRE_ACCOUNT_RESULT_CLOSURE *cls,
  const struct TALER_FullPayto payto_uri,
  const char *conversion_url,
  const char *open_banking_gateway,
  const char *prepared_transfer_url,
  const json_t *debit_restrictions,
  const json_t *credit_restrictions,
  const struct TALER_MasterSignatureP *master_sig,
  const char *bank_label,
  int64_t priority);

/**
 * Obtain information about the enabled wire accounts of the exchange.
 *
 * @param pg the database context
 * @param cb function to call on each account
 * @param cb_cls closure for @a cb
 * @return transaction status code
 */
enum GNUNET_DB_QueryStatus
TALER_EXCHANGEDB_iterate_wire_accounts (struct
                                        TALER_EXCHANGEDB_PostgresContext *pg,
                                        TALER_EXCHANGEDB_WireAccountCallback cb,
                                        TALER_EXCHANGEDB_WIRE_ACCOUNT_RESULT_CLOSURE
                                        *cb_cls);

#endif
