/*
   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/set_instance.h
 * @brief Select the per-instance schema active on the connection
 * @author Christian Grothoff
 */
#ifndef MERCHANT_DATABASE_SET_INSTANCE_H
#define MERCHANT_DATABASE_SET_INSTANCE_H

#include <taler/taler_util.h>
#include "merchantdb_lib.h"


/**
 * Resolve @a instance_id to its merchant_serial and route subsequent
 * per-instance queries on @a pg to the corresponding
 * `merchant_instance_<serial>` schema.  Updates the connection's
 * search_path to "merchant_instance_<serial>, merchant" and stores
 * @a instance_id / serial in the context for use by per-instance
 * call sites and the #PREPARE_INSTANCE macro.
 *
 * Idempotent: a call with an already-active @a instance_id is a no-op.
 *
 * @param pg database connection
 * @param instance_id instance to activate (must be NUL-terminated)
 * @return #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT if the instance was found
 *         and the search_path was updated;
 *         #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if no such instance exists;
 *         a hard or soft error code otherwise
 */
enum GNUNET_DB_QueryStatus
TALER_MERCHANTDB_set_instance (
  struct TALER_MERCHANTDB_PostgresContext *pg,
  const char *instance_id);


#endif
