/*
  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 src/include/taler/merchant/post-private-categories.h
 * @brief C interface for the POST /private/categories endpoint
 * @author Christian Grothoff
 */
#ifndef _TALER_MERCHANT__POST_PRIVATE_CATEGORIES_H
#define _TALER_MERCHANT__POST_PRIVATE_CATEGORIES_H

#include <taler/merchant/common.h>


/**
 * Possible options for the POST /private/categories request.
 */
enum TALER_MERCHANT_PostPrivateCategoriesOption
{
  /**
   * End of list of options.
   */
  TALER_MERCHANT_POST_PRIVATE_CATEGORIES_OPTION_END = 0,

  /**
   * Internationalized names (JSON).
   */
  TALER_MERCHANT_POST_PRIVATE_CATEGORIES_OPTION_NAME_I18N

};


/**
 * Value for an option for the POST /private/categories request.
 */
struct TALER_MERCHANT_PostPrivateCategoriesOptionValue
{

  /**
   * Type of the option being set.
   */
  enum TALER_MERCHANT_PostPrivateCategoriesOption option;

  /**
   * Specific option value.
   */
  union
  {

    /**
     * Value if @e option is
     * #TALER_MERCHANT_POST_PRIVATE_CATEGORIES_OPTION_NAME_I18N.
     */
    const json_t *name_i18n;

  } details;

};


/**
 * Handle for a POST /private/categories request.
 */
struct TALER_MERCHANT_PostPrivateCategoriesHandle;


/**
 * Response details for a POST /private/categories request.
 */
struct TALER_MERCHANT_PostPrivateCategoriesResponse
{

  /**
   * HTTP response details.
   */
  struct TALER_MERCHANT_HttpResponse hr;

  /**
   * Details depending on the HTTP status code.
   */
  union
  {

    /**
     * Details on #MHD_HTTP_OK.
     */
    struct
    {

      /**
       * Numeric identifier of the newly created category.
       */
      uint64_t category_id;

    } ok;

  } details;

};


/**
 * Terminate the list of the options.
 *
 * @return the terminating object
 */
#define TALER_MERCHANT_post_private_categories_option_end_()                \
        (const struct TALER_MERCHANT_PostPrivateCategoriesOptionValue)      \
        {                                                                    \
          .option = TALER_MERCHANT_POST_PRIVATE_CATEGORIES_OPTION_END       \
        }

/**
 * Set internationalized names.
 *
 * @param n names JSON object
 * @return representation of the option
 */
#define TALER_MERCHANT_post_private_categories_option_name_i18n(n)          \
        (const struct TALER_MERCHANT_PostPrivateCategoriesOptionValue)      \
        {                                                                    \
          .option = TALER_MERCHANT_POST_PRIVATE_CATEGORIES_OPTION_NAME_I18N, \
          .details.name_i18n = (n)                                           \
        }


/**
 * Set the requested options for the operation.
 *
 * @param ppch the request to set the options for
 * @param num_options length of the @a options array
 * @param options an array of options
 * @return #GNUNET_OK on success,
 *         #GNUNET_NO on failure,
 *         #GNUNET_SYSERR on internal error
 */
enum GNUNET_GenericReturnValue
TALER_MERCHANT_post_private_categories_set_options_ (
  struct TALER_MERCHANT_PostPrivateCategoriesHandle *ppch,
  unsigned int num_options,
  const struct TALER_MERCHANT_PostPrivateCategoriesOptionValue *options);


/**
 * Set the requested options for the operation.
 *
 * @param ppch the request to set the options for
 * @param ... the list of the options
 * @return #GNUNET_OK on success,
 *         #GNUNET_NO on failure,
 *         #GNUNET_SYSERR on internal error
 */
#define TALER_MERCHANT_post_private_categories_set_options(ppch,...)                \
        TALER_MERCHANT_post_private_categories_set_options_ (                       \
          ppch,                                                                     \
          TALER_MERCHANT_COMMON_OPTIONS_ARRAY_MAX_SIZE,                            \
          ((const struct TALER_MERCHANT_PostPrivateCategoriesOptionValue[])         \
           {__VA_ARGS__, TALER_MERCHANT_post_private_categories_option_end_ () }   \
          ))


/**
 * Set up POST /private/categories operation.
 * Note that you must explicitly start the operation after
 * possibly setting options.
 *
 * @param ctx the context
 * @param url base URL of the merchant backend
 * @param name human-readable name of the category
 * @return handle to operation
 */
struct TALER_MERCHANT_PostPrivateCategoriesHandle *
TALER_MERCHANT_post_private_categories_create (
  struct GNUNET_CURL_Context *ctx,
  const char *url,
  const char *name);


#ifndef TALER_MERCHANT_POST_PRIVATE_CATEGORIES_RESULT_CLOSURE
/**
 * Type of the closure used by
 * the #TALER_MERCHANT_PostPrivateCategoriesCallback.
 */
#define TALER_MERCHANT_POST_PRIVATE_CATEGORIES_RESULT_CLOSURE void
#endif /* TALER_MERCHANT_POST_PRIVATE_CATEGORIES_RESULT_CLOSURE */

/**
 * Callback for a POST /private/categories request.
 *
 * @param cls closure
 * @param cpr response details
 */
typedef void
(*TALER_MERCHANT_PostPrivateCategoriesCallback)(
  TALER_MERCHANT_POST_PRIVATE_CATEGORIES_RESULT_CLOSURE *cls,
  const struct TALER_MERCHANT_PostPrivateCategoriesResponse *cpr);


/**
 * Start POST /private/categories operation.
 *
 * @param[in,out] ppch operation to start
 * @param cb function to call with the merchant's result
 * @param cb_cls closure for @a cb
 * @return status code, #TALER_EC_NONE on success
 */
enum TALER_ErrorCode
TALER_MERCHANT_post_private_categories_start (
  struct TALER_MERCHANT_PostPrivateCategoriesHandle *ppch,
  TALER_MERCHANT_PostPrivateCategoriesCallback cb,
  TALER_MERCHANT_POST_PRIVATE_CATEGORIES_RESULT_CLOSURE *cb_cls);


/**
 * Cancel POST /private/categories operation.  This function must not be
 * called by clients after the TALER_MERCHANT_PostPrivateCategoriesCallback
 * has been invoked (as in those cases it'll be called internally by the
 * implementation already).
 *
 * @param[in] ppch operation to cancel
 */
void
TALER_MERCHANT_post_private_categories_cancel (
  struct TALER_MERCHANT_PostPrivateCategoriesHandle *ppch);


#endif /* _TALER_MERCHANT__POST_PRIVATE_CATEGORIES_H */
