/*
  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/delete-private-orders-ORDER_ID.h
 * @brief C interface for DELETE /private/orders/$ORDER_ID
 * @author Christian Grothoff
 */
#ifndef _TALER_MERCHANT__DELETE_PRIVATE_ORDERS_ORDER_ID_H
#define _TALER_MERCHANT__DELETE_PRIVATE_ORDERS_ORDER_ID_H

#include <taler/merchant/common.h>


/**
 * Handle for a DELETE /private/orders/$ORDER_ID operation.
 */
struct TALER_MERCHANT_DeletePrivateOrderHandle;


/**
 * Set up DELETE /private/orders/$ORDER_ID operation.
 * Note that you must explicitly start the operation after setup.
 *
 * @param ctx curl context
 * @param url merchant backend base URL
 * @param order_id identifier of the order to delete
 * @return handle to operation, NULL on error
 */
struct TALER_MERCHANT_DeletePrivateOrderHandle *
TALER_MERCHANT_delete_private_order_create (
  struct GNUNET_CURL_Context *ctx,
  const char *url,
  const char *order_id);


/**
 * Options for DELETE /private/orders/$ORDER_ID.
 */
enum TALER_MERCHANT_DeletePrivateOrderOption
{
  /**
   * Sentinel value, end of options.
   */
  TALER_MERCHANT_DELETE_PRIVATE_ORDER_OPTION_END = 0,

  /**
   * If set, force deletion even if order has payments.
   * Value type: none (presence of option means force=true).
   */
  TALER_MERCHANT_DELETE_PRIVATE_ORDER_OPTION_FORCE
};


/**
 * Value for a DELETE /private/orders/$ORDER_ID option.
 */
struct TALER_MERCHANT_DeletePrivateOrderOptionValue
{
  /**
   * Which option is being set.
   */
  enum TALER_MERCHANT_DeletePrivateOrderOption option;
};


/**
 * Ends list of options.
 */
#define TALER_MERCHANT_delete_private_order_set_option_end() \
        (struct TALER_MERCHANT_DeletePrivateOrderOptionValue) \
        { .option = TALER_MERCHANT_DELETE_PRIVATE_ORDER_OPTION_END }

/**
 * Force deletion even if the order has been claimed.
 */
#define TALER_MERCHANT_delete_private_order_set_option_force() \
        (struct TALER_MERCHANT_DeletePrivateOrderOptionValue) \
        { .option = TALER_MERCHANT_DELETE_PRIVATE_ORDER_OPTION_FORCE }


/**
 * Set options for DELETE /private/orders/$ORDER_ID operation.
 *
 * @param[in,out] handle the handle to set options for
 * @param num_options length of the @a options array
 * @param options array of option values (terminated with _END)
 * @return #GNUNET_OK on success,
 *         #GNUNET_NO on failure,
 *         #GNUNET_SYSERR on internal error
 */
enum GNUNET_GenericReturnValue
TALER_MERCHANT_delete_private_order_set_options_ (
  struct TALER_MERCHANT_DeletePrivateOrderHandle *handle,
  unsigned int num_options,
  const struct TALER_MERCHANT_DeletePrivateOrderOptionValue options[]);


/**
 * Maximum number of options for set_options macro.
 */
#define TALER_MERCHANT_DELETE_PRIVATE_ORDER_OPTIONS_ARRAY_MAX_SIZE 4

/**
 * Set options for DELETE /private/orders/$ORDER_ID operation.
 * Variadic macro wrapper around
 * #TALER_MERCHANT_delete_private_order_set_options_().
 *
 * @param handle the handle to set options for
 * @param ... option values (automatically terminated with _END)
 * @return #GNUNET_OK on success,
 *         #GNUNET_NO on failure,
 *         #GNUNET_SYSERR on internal error
 */
#define TALER_MERCHANT_delete_private_order_set_options(handle, ...) \
        TALER_MERCHANT_delete_private_order_set_options_ ( \
          handle, \
          TALER_MERCHANT_DELETE_PRIVATE_ORDER_OPTIONS_ARRAY_MAX_SIZE, \
          ((const struct TALER_MERCHANT_DeletePrivateOrderOptionValue[]) \
           {__VA_ARGS__,                                                 \
            TALER_MERCHANT_delete_private_order_set_option_end () }      \
          ))

/**
 * Response details for a DELETE /private/orders/$ORDER_ID request.
 */
struct TALER_MERCHANT_DeletePrivateOrderResponse
{
  /**
   * HTTP response details.
   */
  struct TALER_MERCHANT_HttpResponse hr;
};


#ifndef TALER_MERCHANT_DELETE_PRIVATE_ORDER_RESULT_CLOSURE
/**
 * Type of the closure used by
 * the #TALER_MERCHANT_DeletePrivateOrderCallback.
 */
#define TALER_MERCHANT_DELETE_PRIVATE_ORDER_RESULT_CLOSURE void
#endif /* TALER_MERCHANT_DELETE_PRIVATE_ORDER_RESULT_CLOSURE */

/**
 * Type of the function that receives the result of a
 * DELETE /private/orders/$ORDER_ID request.
 *
 * @param cls closure
 * @param result result returned by the HTTP server
 */
typedef void
(*TALER_MERCHANT_DeletePrivateOrderCallback)(
  TALER_MERCHANT_DELETE_PRIVATE_ORDER_RESULT_CLOSURE *cls,
  const struct TALER_MERCHANT_DeletePrivateOrderResponse *result);


/**
 * Start DELETE /private/orders/$ORDER_ID operation.
 *
 * @param[in,out] handle operation to start
 * @param cb function to call with the result
 * @param cb_cls closure for @a cb
 * @return status code, #TALER_EC_NONE on success
 */
enum TALER_ErrorCode
TALER_MERCHANT_delete_private_order_start (
  struct TALER_MERCHANT_DeletePrivateOrderHandle *handle,
  TALER_MERCHANT_DeletePrivateOrderCallback cb,
  TALER_MERCHANT_DELETE_PRIVATE_ORDER_RESULT_CLOSURE *cb_cls);


/**
 * Cancel DELETE /private/orders/$ORDER_ID operation.
 * This function must not be called by clients after the
 * callback has been invoked.
 *
 * @param[in] handle operation to cancel
 */
void
TALER_MERCHANT_delete_private_order_cancel (
  struct TALER_MERCHANT_DeletePrivateOrderHandle *handle);


#endif /* _TALER_MERCHANT__DELETE_PRIVATE_ORDERS_ORDER_ID_H */
