/*
  This file is part of Anastasis
  Copyright (C) 2020-2022 Anastasis SARL

  Anastasis is free software; you can redistribute it and/or modify it under the
  terms of the GNU Affero General Public License as published by the Free Software
  Foundation; either version 3, or (at your option) any later version.

  Anastasis 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 Affero General Public License for more details.

  You should have received a copy of the GNU Affero General Public License along with
  Anastasis; see the file COPYING.GPL.  If not, see <http://www.gnu.org/licenses/>
*/
/**
 * @file stasis/insert_auth_iban_in.c
 * @brief Anastasis database: insert auth iban in
 * @author Christian Grothoff
 */
#include "platform.h"
#include "anastasis-db_pg.h"
#include "anastasis/anastasis-database/insert_auth_iban_in.h"
#include "anastasis/anastasis-database/transaction.h"
#include "anastasis/anastasis-database/preflight.h"
#include <taler/taler_pq_lib.h>


/**
 * Store inbound IBAN payment made for authentication.
 *
 * @param wire_reference unique identifier inside LibEuFin/Nexus
 * @param wire_subject subject of the wire transfer
 * @param amount how much was transferred
 * @param debit_account account that was debited
 * @param credit_account Anastasis operator account credited
 * @param execution_date when was the transfer made
 * @return transaction status
 */
enum GNUNET_DB_QueryStatus
ANASTASIS_DB_insert_auth_iban_in (
  uint64_t wire_reference,
  const char *wire_subject,
  const struct TALER_Amount *amount,
  const char *debit_account,
  const char *credit_account,
  struct GNUNET_TIME_Timestamp execution_date)
{
  struct GNUNET_PQ_QueryParam params[] = {
    GNUNET_PQ_query_param_uint64 (&wire_reference),
    GNUNET_PQ_query_param_string (wire_subject),
    TALER_PQ_query_param_amount (pg->conn,
                                 amount),
    GNUNET_PQ_query_param_string (debit_account),
    GNUNET_PQ_query_param_string (credit_account),
    GNUNET_PQ_query_param_timestamp (&execution_date),
    GNUNET_PQ_query_param_end
  };

  PREPARE ("insert_auth_iban_in",
           "INSERT INTO anastasis_auth_iban_in "
           "(wire_reference"
           ",wire_subject"
           ",credit"
           ",debit_account_details"
           ",credit_account_details"
           ",execution_date"
           ") VALUES "
           "($1, $2, $3, $4, $5, $6);");
  return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                             "insert_auth_iban_in",
                                             params);
}


/* end of insert_auth_iban_in.c */
