/*
  This file is part of TALER
  Copyright (C) 2014-2026 Taler Systems SA

  TALER is free software; you can redistribute it and/or modify it under the
  terms of the GNU Lesser General Public License as published by the Free Software
  Foundation; either version 2.1, 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 Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public License along with
  TALER; see the file COPYING.LGPL.  If not, see
  <http://www.gnu.org/licenses/>
*/
/**
 * @file include/taler/taler-merchant/post-private-products-PRODUCT_ID-lock.h
 * @brief C interface for POST /private/products/$PRODUCT_ID/lock of the merchant backend
 * @author Christian Grothoff
 */
#ifndef _TALER_MERCHANT__POST_PRIVATE_PRODUCTS_PRODUCT_ID_LOCK_H
#define _TALER_MERCHANT__POST_PRIVATE_PRODUCTS_PRODUCT_ID_LOCK_H

#include <taler/taler-merchant/common.h>


/**
 * Handle for a POST /private/products/$PRODUCT_ID/lock request.
 */
struct TALER_MERCHANT_ProductLockHandle;


/**
 * Callback for a POST /private/products/$PRODUCT_ID/lock request.
 *
 * @param cls closure
 * @param hr HTTP response details
 */
typedef void
(*TALER_MERCHANT_ProductLockCallback)(
  void *cls,
  const struct TALER_MERCHANT_HttpResponse *hr);


/**
 * Issue a POST /private/products/$PRODUCT_ID/lock request (simple form,
 * integer quantities only).
 *
 * @param ctx CURL context to use
 * @param backend_url base URL of the merchant backend
 * @param product_id identifier of the product to lock
 * @param uuid idempotency UUID for this lock operation
 * @param duration how long to lock the inventory
 * @param quantity number of units to lock
 * @param cb callback to invoke with the result
 * @param cb_cls closure for @a cb
 * @return handle for the request, NULL on hard error
 */
struct TALER_MERCHANT_ProductLockHandle *
TALER_MERCHANT_product_lock (struct GNUNET_CURL_Context *ctx,
                             const char *backend_url,
                             const char *product_id,
                             const char *uuid,
                             struct GNUNET_TIME_Relative duration,
                             uint32_t quantity,
                             TALER_MERCHANT_ProductLockCallback cb,
                             void *cb_cls);


/**
 * Issue a POST /private/products/$PRODUCT_ID/lock request with fractional
 * quantity support.
 *
 * @param ctx CURL context to use
 * @param backend_url base URL of the merchant backend
 * @param product_id identifier of the product to lock
 * @param uuid idempotency UUID for this lock operation
 * @param duration how long to lock the inventory
 * @param quantity integer part of the quantity to lock
 * @param quantity_frac fractional part of the quantity
 * @param use_fractional_quantity if true, use fractional quantity
 * @param cb callback to invoke with the result
 * @param cb_cls closure for @a cb
 * @return handle for the request, NULL on hard error
 */
struct TALER_MERCHANT_ProductLockHandle *
TALER_MERCHANT_product_lock2 (struct GNUNET_CURL_Context *ctx,
                              const char *backend_url,
                              const char *product_id,
                              const char *uuid,
                              struct GNUNET_TIME_Relative duration,
                              uint64_t quantity,
                              uint32_t quantity_frac,
                              bool use_fractional_quantity,
                              TALER_MERCHANT_ProductLockCallback cb,
                              void *cb_cls);


/**
 * Cancel a POST /private/products/$PRODUCT_ID/lock request.
 *
 * @param[in] plh handle to cancel
 */
void
TALER_MERCHANT_product_lock_cancel (
  struct TALER_MERCHANT_ProductLockHandle *plh);


#endif
