/*
   This file is part of TALER
   Copyright (C) 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/auditordb/insert_aml_staff.c
 * @brief Implementation of the insert_aml_staff function for Postgres
 * @author Christian Grothoff
 */
#include "taler/taler_pq_lib.h"
#include "pg_helper.h"
#include "auditor-database/insert_aml_staff.h"


enum GNUNET_DB_QueryStatus
TALER_AUDITORDB_insert_aml_staff (
  struct TALER_AUDITORDB_PostgresContext *pg,
  const struct TALER_AmlOfficerPublicKeyP *decider_pub,
  const char *decider_name,
  bool is_active,
  bool read_only,
  bool master_sig_valid,
  struct GNUNET_TIME_Timestamp last_change)
{
  struct GNUNET_PQ_QueryParam params[] = {
    GNUNET_PQ_query_param_auto_from_type (decider_pub),
    GNUNET_PQ_query_param_string (decider_name),
    GNUNET_PQ_query_param_bool (is_active),
    GNUNET_PQ_query_param_bool (read_only),
    GNUNET_PQ_query_param_bool (master_sig_valid),
    GNUNET_PQ_query_param_timestamp (&last_change),
    GNUNET_PQ_query_param_end
  };

  PREPARE (pg,
           "insert_aml_staff",
           "INSERT INTO auditor_aml_staff "
           "(decider_pub,"
           " decider_name,"
           " is_active,"
           " read_only,"
           " master_sig_valid,"
           " last_change"
           ") VALUES ($1,$2,$3,$4,$5,$6)"
           " ON CONFLICT (decider_pub, last_change) DO NOTHING;");
  return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                             "insert_aml_staff",
                                             params);
}
