/*
   This file is part of Challenger
   Copyright (C) 2023 Taler Systems SA

   Challenger 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.

   Challenger 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
   Challenger; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
 */
/**
 * @file src/include/challenger-database/do_insert_validation.h
 * @brief implementation of the do_insert_validation function for Postgres
 * @author Christian Grothoff
 */
#ifndef CHALLENGER_DATABASE_DO_INSERT_VALIDATION_H
#define CHALLENGER_DATABASE_DO_INSERT_VALIDATION_H

#include <taler/taler_util.h>
#include <taler/taler_json_lib.h>
#include "challenger_util.h"
#include "challenger_database_lib.h"


/**
 * Start validation process by setting up a validation entry. Allows
 * the respective user who learns the @a nonce to later begin the
 * process.
 *
 * Authenticates the client against @a client_secret and charges it for
 * the validation (by incrementing @e validation_counter) in the same
 * statement that inserts the row, so the counter moves if and only if
 * the validation was actually created.
 *
 * @param ctx database context
 * @param client_id ID of the client
 * @param client_secret secret of the client
 * @param nonce unique nonce to use to identify the validation
 * @param expiration_time when will the validation expire
 * @param initial_address address the user should validate,
 *        NULL if the user should enter it themselves
 * @return transaction status, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if
 *         there is no such client or @a client_secret does not match
 */
enum GNUNET_DB_QueryStatus
CHALLENGERDB_do_insert_validation (
  struct CHALLENGERDB_PostgresContext *ctx,
  uint64_t client_id,
  const char *client_secret,
  const struct CHALLENGER_ValidationNonceP *nonce,
  struct GNUNET_TIME_Absolute expiration_time,
  const json_t *initial_address);

#endif
