/*
   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/do_insert_known_coin.h
 * @brief implementation of the do_insert_known_coin function for Postgres
 * @author Christian Grothoff
 */
#ifndef EXCHANGE_DATABASE_DO_INSERT_KNOWN_COIN_H
#define EXCHANGE_DATABASE_DO_INSERT_KNOWN_COIN_H

#include "exchangedb_lib.h"

/**
 * Possible status codes from making sure a coin is known.
   */
enum TALER_EXCHANGEDB_CoinKnownStatus
{
  /**
   * The coin was successfully added.
   */
  TALER_EXCHANGEDB_CKS_ADDED = 1,

  /**
   * The coin was already present.
   */
  TALER_EXCHANGEDB_CKS_PRESENT = 0,

  /**
   * Serialization failure.
   */
  TALER_EXCHANGEDB_CKS_SOFT_FAIL = -1,

  /**
   * Hard database failure.
   */
  TALER_EXCHANGEDB_CKS_HARD_FAIL = -2,

  /**
   * Conflicting coin (different denomination key) already in database.
   */
  TALER_EXCHANGEDB_CKS_DENOM_CONFLICT = -3,

  /**
   * Conflicting coin (expected NULL age hash) already in database.
   */
  TALER_EXCHANGEDB_CKS_AGE_CONFLICT_EXPECTED_NULL = -4,

  /**
   * Conflicting coin (unexpected NULL age hash) already in database.
   */
  TALER_EXCHANGEDB_CKS_AGE_CONFLICT_EXPECTED_NON_NULL = -5,

  /**
   * Conflicting coin (different age hash) already in database.
   */
  TALER_EXCHANGEDB_CKS_AGE_CONFLICT_VALUE_DIFFERS = -6,

};


/**
 * Make sure the given @a coin is known to the database.
 *
 * @param pg the database context
 * @param coin the coin that must be made known
 * @param[out] known_coin_id set to the unique row of the coin
 * @param[out] denom_hash set to the denomination hash of the existing
 *             coin (for conflict error reporting)
 * @param[out] h_age_commitment  set to the conflicting age commitment hash on conflict
 * @return database transaction status, non-negative on success
 */
enum TALER_EXCHANGEDB_CoinKnownStatus
TALER_EXCHANGEDB_do_insert_known_coin (struct TALER_EXCHANGEDB_PostgresContext *
                                       pg,
                                       const struct TALER_CoinPublicInfo *coin,
                                       uint64_t *known_coin_id,
                                       struct TALER_DenominationHashP *
                                       denom_hash,
                                       struct TALER_AgeCommitmentHashP *
                                       h_age_commitment)
;

#endif
