/*
  This file is part of Anastasis
  Copyright (C) 2026 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 include/anastasis/anastasis-database/update_totp_counter.h
 * @brief Anastasis database: accept a TOTP time step counter once
 * @author Christian Grothoff
 */
#ifndef ANASTASIS_DATABASE_UPDATE_TOTP_COUNTER_H
#define ANASTASIS_DATABASE_UPDATE_TOTP_COUNTER_H

#include <gnunet/gnunet_util_lib.h>
#include <gnunet/gnunet_db_lib.h>
#include "anastasis_service.h"
#include "anastasis/anastasis-database/common.h"

/**
 * Consume the TOTP time step @a counter for @a truth_uuid.
 *
 * A TOTP code is valid for a whole window of time steps, so it can be
 * replayed until that window passes unless the provider remembers which step
 * it already honoured (RFC 6238, section 5.2).  Succeeds only if @a counter is
 * strictly newer than the last counter accepted for this truth, and records it
 * in the same statement, so that two requests carrying the same code cannot
 * both succeed.
 *
 * @param truth_uuid identification of the challenge the code belongs to
 * @param counter time step counter the code was computed for
 * @return #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT if the counter was accepted,
 *         #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if it is a replay or the
 *         truth does not exist, otherwise the error status
 */
enum GNUNET_DB_QueryStatus
ANASTASIS_DB_update_totp_counter (
  const struct ANASTASIS_CRYPTO_TruthUUIDP *truth_uuid,
  uint64_t counter);

#endif
