/*
   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 Affero 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 Affero General Public License for more details.

   You should have received a copy of the GNU Affero General Public License along with
   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
 */
/**
 * @file include/taler/exchange/get-aml-OFFICER_PUB-kyc-statistics-NAMES.h
 * @brief C interface for GET /aml/$OFFICER_PUB/kyc-statistics/$NAMES
 * @author Christian Grothoff
 */
#ifndef _TALER_EXCHANGE__GET_AML_OFFICER_PUB_KYC_STATISTICS_NAMES_H
#define _TALER_EXCHANGE__GET_AML_OFFICER_PUB_KYC_STATISTICS_NAMES_H

#include <taler/exchange/common.h>

/**
 * Possible options we can set for the GET kyc-statistics request.
 */
enum TALER_EXCHANGE_GetAmlKycStatisticsOption
{
  /**
   * End of list of options.
   */
  TALER_EXCHANGE_GET_AML_KYC_STATISTICS_OPTION_END = 0,

  /**
   * Start date for the statistics window (inclusive).
   * If not set, the start time of the exchange operation is used.
   */
  TALER_EXCHANGE_GET_AML_KYC_STATISTICS_OPTION_START_DATE,

  /**
   * End date for the statistics window (exclusive).
   * If not set, the current date is used.
   */
  TALER_EXCHANGE_GET_AML_KYC_STATISTICS_OPTION_END_DATE

};


/**
 * Value for an option for the GET kyc-statistics request.
 */
struct TALER_EXCHANGE_GetAmlKycStatisticsOptionValue
{

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

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

    /**
     * Value if @e option is TALER_EXCHANGE_GET_AML_KYC_STATISTICS_OPTION_START_DATE.
     */
    struct GNUNET_TIME_Timestamp start_date;

    /**
     * Value if @e option is TALER_EXCHANGE_GET_AML_KYC_STATISTICS_OPTION_END_DATE.
     */
    struct GNUNET_TIME_Timestamp end_date;

  } details;

};


/**
 * Handle for an operation to GET /aml/$OFFICER_PUB/kyc-statistics/$NAMES.
 */
struct TALER_EXCHANGE_GetAmlKycStatisticsHandle;


/**
 * Set up GET /aml/$OPUB/kyc-statistics/$NAMES operation.
 * Note that you must explicitly start the operation after
 * possibly setting options.
 *
 * @param ctx the context
 * @param url base URL of the exchange
 * @param officer_priv private key of the officer
 * @param names space-separated list of event type names to count
 * @return handle to operation
 */
struct TALER_EXCHANGE_GetAmlKycStatisticsHandle *
TALER_EXCHANGE_get_aml_kyc_statistics_create (
  struct GNUNET_CURL_Context *ctx,
  const char *url,
  const struct TALER_AmlOfficerPrivateKeyP *officer_priv,
  const char *names);


/**
 * Terminate the list of the options.
 *
 * @return the terminating object of struct TALER_EXCHANGE_GetAmlKycStatisticsOptionValue
 */
#define TALER_EXCHANGE_get_aml_kyc_statistics_option_end_()               \
        (const struct TALER_EXCHANGE_GetAmlKycStatisticsOptionValue)      \
        {                                                                  \
          .option = TALER_EXCHANGE_GET_AML_KYC_STATISTICS_OPTION_END      \
        }

/**
 * Set start date for the statistics window.
 *
 * @param d start date (inclusive)
 * @return representation of the option as a struct TALER_EXCHANGE_GetAmlKycStatisticsOptionValue
 */
#define TALER_EXCHANGE_get_aml_kyc_statistics_option_start_date(d)             \
        (const struct TALER_EXCHANGE_GetAmlKycStatisticsOptionValue)           \
        {                                                                       \
          .option = TALER_EXCHANGE_GET_AML_KYC_STATISTICS_OPTION_START_DATE,   \
          .details.start_date = (d)                                             \
        }

/**
 * Set end date for the statistics window.
 *
 * @param d end date (exclusive)
 * @return representation of the option as a struct TALER_EXCHANGE_GetAmlKycStatisticsOptionValue
 */
#define TALER_EXCHANGE_get_aml_kyc_statistics_option_end_date(d)               \
        (const struct TALER_EXCHANGE_GetAmlKycStatisticsOptionValue)           \
        {                                                                       \
          .option = TALER_EXCHANGE_GET_AML_KYC_STATISTICS_OPTION_END_DATE,     \
          .details.end_date = (d)                                               \
        }


/**
 * Set the requested options for the operation.
 *
 * If any option fail other options may be or may be not applied.
 *
 * @param aksh 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_EXCHANGE_get_aml_kyc_statistics_set_options_ (
  struct TALER_EXCHANGE_GetAmlKycStatisticsHandle *aksh,
  unsigned int num_options,
  const struct TALER_EXCHANGE_GetAmlKycStatisticsOptionValue *options);


/**
 * Set the requested options for the operation.
 *
 * If any option fail other options may be or may be not applied.
 *
 * It should be used with helpers that create required options, for example:
 *
 * TALER_EXCHANGE_get_aml_kyc_statistics_set_options (
 *   aksh,
 *   TALER_EXCHANGE_get_aml_kyc_statistics_option_start_date (t_start),
 *   TALER_EXCHANGE_get_aml_kyc_statistics_option_end_date (t_end));
 *
 * @param aksh the request to set the options for
 * @param ... the list of the options, each option must be created
 *            by helpers TALER_EXCHANGE_get_aml_kyc_statistics_option_NAME(VALUE)
 * @return #GNUNET_OK on success,
 *         #GNUNET_NO on failure,
 *         #GNUNET_SYSERR on internal error
 */
#define TALER_EXCHANGE_get_aml_kyc_statistics_set_options(aksh,...)               \
        TALER_EXCHANGE_get_aml_kyc_statistics_set_options_ (                      \
          aksh,                                                                    \
          TALER_EXCHANGE_COMMON_OPTIONS_ARRAY_MAX_SIZE,                           \
          ((const struct TALER_EXCHANGE_GetAmlKycStatisticsOptionValue[])         \
           {__VA_ARGS__, TALER_EXCHANGE_get_aml_kyc_statistics_option_end_ () }   \
          ))


/**
 * A single event counter returned for one statistic name.
 * Since protocol v30 (rev 1), the response returns an array of these.
 */
struct TALER_EXCHANGE_GetAmlKycStatisticsEventCounter
{
  /**
   * Name of the statistic being reported.
   */
  const char *name;

  /**
   * Number of events of the specified type in the given time range.
   */
  uint64_t counter;
};


/**
 * Response from a GET /aml/$OFFICER_PUB/kyc-statistics/$NAMES request.
 */
struct TALER_EXCHANGE_GetAmlKycStatisticsResponse
{
  /**
   * HTTP response data
   */
  struct TALER_EXCHANGE_HttpResponse hr;

  /**
   * Response details depending on the HTTP status.
   */
  union
  {
    /**
     * Details if HTTP status is #MHD_HTTP_OK.
     */
    struct
    {

      /**
       * Array of event counters, one per requested name.
       */
      const struct TALER_EXCHANGE_GetAmlKycStatisticsEventCounter *statistics;

      /**
       * Length of the @e statistics array.
       */
      size_t statistics_length;

    } ok;

  } details;

};


#ifndef TALER_EXCHANGE_GET_AML_KYC_STATISTICS_RESULT_CLOSURE
/**
 * Type of the closure used by
 * the #TALER_EXCHANGE_GetAmlKycStatisticsCallback.
 */
#define TALER_EXCHANGE_GET_AML_KYC_STATISTICS_RESULT_CLOSURE void
#endif /* TALER_EXCHANGE_GET_AML_KYC_STATISTICS_RESULT_CLOSURE */

/**
 * Type of the function that receives the result of a
 * GET /aml/$OFFICER_PUB/kyc-statistics/$NAMES request.
 *
 * @param cls closure
 * @param result result returned by the HTTP server
 */
typedef void
(*TALER_EXCHANGE_GetAmlKycStatisticsCallback)(
  TALER_EXCHANGE_GET_AML_KYC_STATISTICS_RESULT_CLOSURE *cls,
  const struct TALER_EXCHANGE_GetAmlKycStatisticsResponse *result);


/**
 * Start GET /aml/$OPUB/kyc-statistics/$NAMES operation.
 *
 * @param[in,out] aksh operation to start
 * @param cb function to call with the exchange's result
 * @param cb_cls closure for @a cb
 * @return status code, #TALER_EC_NONE on success
 */
enum TALER_ErrorCode
TALER_EXCHANGE_get_aml_kyc_statistics_start (
  struct TALER_EXCHANGE_GetAmlKycStatisticsHandle *aksh,
  TALER_EXCHANGE_GetAmlKycStatisticsCallback cb,
  TALER_EXCHANGE_GET_AML_KYC_STATISTICS_RESULT_CLOSURE *cb_cls);


/**
 * Cancel GET /aml/$OPUB/kyc-statistics/$NAMES operation.  This function
 * must not be called by clients after the
 * TALER_EXCHANGE_GetAmlKycStatisticsCallback has been invoked
 * (as in those cases it'll be called internally by the
 * implementation already).
 *
 * @param[in] aksh operation to cancel
 */
void
TALER_EXCHANGE_get_aml_kyc_statistics_cancel (
  struct TALER_EXCHANGE_GetAmlKycStatisticsHandle *aksh);


#endif /* _TALER_EXCHANGE__GET_AML_OFFICER_PUB_KYC_STATISTICS_NAMES_H */
