/*
  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.h
 * @brief C interface for POST /private/products of the merchant backend
 * @author Christian Grothoff
 */
#ifndef _TALER_MERCHANT__POST_PRIVATE_PRODUCTS_H
#define _TALER_MERCHANT__POST_PRIVATE_PRODUCTS_H

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


/**
 * Handle for a POST /private/products request.
 */
struct TALER_MERCHANT_ProductsPostHandle;


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


/**
 * Issue a POST /private/products request (simple form).
 *
 * @param ctx CURL context to use
 * @param backend_url base URL of the merchant backend
 * @param product_id identifier for the new product
 * @param description human-readable product description
 * @param description_i18n internationalized descriptions (JSON), or NULL
 * @param unit unit of measurement
 * @param price unit price
 * @param image base64-encoded image, or empty string
 * @param taxes tax information (JSON array), or NULL
 * @param total_stock total stock (-1 for unlimited)
 * @param address storage location (JSON), or NULL
 * @param next_restock expected restock time
 * @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_ProductsPostHandle *
TALER_MERCHANT_products_post (
  struct GNUNET_CURL_Context *ctx,
  const char *backend_url,
  const char *product_id,
  const char *description,
  const json_t *description_i18n,
  const char *unit,
  const struct TALER_Amount *price,
  const char *image,
  const json_t *taxes,
  int64_t total_stock,
  const json_t *address,
  struct GNUNET_TIME_Timestamp next_restock,
  TALER_MERCHANT_ProductsPostCallback cb,
  void *cb_cls);


/**
 * Issue a POST /private/products request with minimum age.
 *
 * @param ctx CURL context to use
 * @param backend_url base URL of the merchant backend
 * @param product_id identifier for the new product
 * @param description human-readable product description
 * @param description_i18n internationalized descriptions (JSON), or NULL
 * @param unit unit of measurement
 * @param price unit price
 * @param image base64-encoded image, or empty string
 * @param taxes tax information (JSON array), or NULL
 * @param total_stock total stock (-1 for unlimited)
 * @param address storage location (JSON), or NULL
 * @param next_restock expected restock time
 * @param minimum_age minimum age requirement (0 for none)
 * @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_ProductsPostHandle *
TALER_MERCHANT_products_post2 (
  struct GNUNET_CURL_Context *ctx,
  const char *backend_url,
  const char *product_id,
  const char *description,
  const json_t *description_i18n,
  const char *unit,
  const struct TALER_Amount *price,
  const char *image,
  const json_t *taxes,
  int64_t total_stock,
  const json_t *address,
  struct GNUNET_TIME_Timestamp next_restock,
  uint32_t minimum_age,
  TALER_MERCHANT_ProductsPostCallback cb,
  void *cb_cls);


/**
 * Issue a POST /private/products request with category support.
 *
 * @param ctx CURL context to use
 * @param backend_url base URL of the merchant backend
 * @param product_id identifier for the new product
 * @param description human-readable product description
 * @param description_i18n internationalized descriptions (JSON), or NULL
 * @param unit unit of measurement
 * @param price unit price
 * @param image base64-encoded image, or empty string
 * @param taxes tax information (JSON array), or NULL
 * @param total_stock total stock (-1 for unlimited)
 * @param address storage location (JSON), or NULL
 * @param next_restock expected restock time
 * @param minimum_age minimum age requirement (0 for none)
 * @param num_cats number of category IDs in @a cats
 * @param cats array of category IDs
 * @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_ProductsPostHandle *
TALER_MERCHANT_products_post3 (
  struct GNUNET_CURL_Context *ctx,
  const char *backend_url,
  const char *product_id,
  const char *description,
  const json_t *description_i18n,
  const char *unit,
  const struct TALER_Amount *price,
  const char *image,
  const json_t *taxes,
  int64_t total_stock,
  const json_t *address,
  struct GNUNET_TIME_Timestamp next_restock,
  uint32_t minimum_age,
  unsigned int num_cats,
  const uint64_t *cats,
  TALER_MERCHANT_ProductsPostCallback cb,
  void *cb_cls);


/**
 * Issue a POST /private/products request with full unit/fraction support.
 *
 * @param ctx CURL context to use
 * @param backend_url base URL of the merchant backend
 * @param product_id identifier for the new product
 * @param description human-readable product description
 * @param description_i18n internationalized descriptions (JSON), or NULL
 * @param unit unit of measurement
 * @param unit_prices array of unit prices (for different payment options)
 * @param unit_price_len number of prices in @a unit_prices
 * @param image base64-encoded image, or empty string
 * @param taxes tax information (JSON array), or NULL
 * @param total_stock integer part of total stock (-1 for unlimited)
 * @param total_stock_frac fractional part of total stock
 * @param unit_allow_fraction whether fractional quantities are allowed
 * @param unit_precision_level precision level for fractions, or NULL
 * @param address storage location (JSON), or NULL
 * @param next_restock expected restock time
 * @param minimum_age minimum age requirement (0 for none)
 * @param num_cats number of category IDs in @a cats
 * @param cats array of category IDs
 * @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_ProductsPostHandle *
TALER_MERCHANT_products_post4 (
  struct GNUNET_CURL_Context *ctx,
  const char *backend_url,
  const char *product_id,
  const char *description,
  const json_t *description_i18n,
  const char *unit,
  const struct TALER_Amount *unit_prices,
  size_t unit_price_len,
  const char *image,
  const json_t *taxes,
  int64_t total_stock,
  uint32_t total_stock_frac,
  bool unit_allow_fraction,
  const uint32_t *unit_precision_level,
  const json_t *address,
  struct GNUNET_TIME_Timestamp next_restock,
  uint32_t minimum_age,
  unsigned int num_cats,
  const uint64_t *cats,
  TALER_MERCHANT_ProductsPostCallback cb,
  void *cb_cls);


/**
 * Cancel a POST /private/products request.
 *
 * @param[in] pph handle to cancel
 */
void
TALER_MERCHANT_products_post_cancel (
  struct TALER_MERCHANT_ProductsPostHandle *pph);


#endif
