/*
   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/include/merchant-database/update_token_family_key_expiration.h
 * @brief implementation of the update_token_family_key_expiration function for Postgres
 * @author Christian Grothoff
 */
#ifndef MERCHANT_DATABASE_UPDATE_TOKEN_FAMILY_KEY_EXPIRATION_H
#define MERCHANT_DATABASE_UPDATE_TOKEN_FAMILY_KEY_EXPIRATION_H

#include <gnunet/gnunet_common.h>
#include <taler/taler_util.h>
#include <taler/taler_json_lib.h>
#include "merchantdb_lib.h"


/**
 * Extend the lifetime of the private key(s) of the token family
 * @a token_family_slug that cover the validity period @a valid_at, so that
 * they can still be used to sign tokens until @a sign_until.  Keys whose
 * private key already lives at least that long (and keys whose private key
 * was already deleted) are left alone.
 *
 * This is what keeps the backend from minting a second key for a validity
 * period that is already covered, just because a later order has a pay
 * deadline beyond the retention deadline of the existing key.
 *
 * @param pg database context
 * @param instance_id instance to update the token family key for
 * @param token_family_slug slug of the token family to update
 * @param valid_at only extend keys with a validity period that includes this time
 * @param sign_until the private key must be usable for signing until this time
 * @return database result code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if no
 *         key needed extending
 */
enum GNUNET_DB_QueryStatus
TALER_MERCHANTDB_update_token_family_key_expiration (
  struct TALER_MERCHANTDB_PostgresContext *pg,
  const char *instance_id,
  const char *token_family_slug,
  struct GNUNET_TIME_Timestamp valid_at,
  struct GNUNET_TIME_Timestamp sign_until);


#endif
