/*
  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/get-private-tokenfamilies-TOKEN_FAMILY_SLUG.h
 * @brief C interface for GET /private/tokenfamilies/$TOKEN_FAMILY_SLUG
 *        of the merchant backend
 * @author Christian Grothoff
 */
#ifndef _TALER_MERCHANT__GET_PRIVATE_TOKENFAMILIES_TOKEN_FAMILY_SLUG_H
#define _TALER_MERCHANT__GET_PRIVATE_TOKENFAMILIES_TOKEN_FAMILY_SLUG_H

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


/**
 * Handle for a GET /private/tokenfamilies/$TOKEN_FAMILY_SLUG request.
 */
struct TALER_MERCHANT_TokenFamilyGetHandle;


/**
 * Response details for a GET /private/tokenfamilies/$TOKEN_FAMILY_SLUG request.
 */
struct TALER_MERCHANT_TokenFamilyGetResponse
{

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

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

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

      /**
       * URL-safe slug identifier of the token family.
       */
      const char *slug;

      /**
       * Human-readable name.
       */
      const char *name;

      /**
       * Human-readable description.
       */
      const char *description;

      /**
       * Internationalized descriptions (JSON), or NULL.
       */
      const json_t *description_i18n;

      /**
       * Extra data associated with this token family (JSON), or NULL.
       */
      const json_t *extra_data;

      /**
       * Start of validity period.
       */
      struct GNUNET_TIME_Timestamp valid_after;

      /**
       * End of validity period.
       */
      struct GNUNET_TIME_Timestamp valid_before;

      /**
       * Duration of individual token validity.
       */
      struct GNUNET_TIME_Relative duration;

      /**
       * Granularity for validity period alignment.
       */
      struct GNUNET_TIME_Relative validity_granularity;

      /**
       * Offset from purchase time to start of validity.
       */
      struct GNUNET_TIME_Relative start_offset;

      /**
       * Kind of token family ("subscription" or "discount").
       */
      const char *kind;

      /**
       * Total number of tokens issued.
       */
      uint64_t issued;

      /**
       * Total number of tokens used.
       */
      uint64_t used;

    } ok;

  } details;

};


/**
 * Callback for a GET /private/tokenfamilies/$TOKEN_FAMILY_SLUG request.
 *
 * @param cls closure
 * @param tfgr response details
 */
typedef void
(*TALER_MERCHANT_TokenFamilyGetCallback)(
  void *cls,
  const struct TALER_MERCHANT_TokenFamilyGetResponse *tfgr);


/**
 * Issue a GET /private/tokenfamilies/$TOKEN_FAMILY_SLUG request.
 *
 * @param ctx CURL context to use
 * @param backend_url base URL of the merchant backend
 * @param token_family_slug slug of the token family to retrieve
 * @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_TokenFamilyGetHandle *
TALER_MERCHANT_token_family_get (
  struct GNUNET_CURL_Context *ctx,
  const char *backend_url,
  const char *token_family_slug,
  TALER_MERCHANT_TokenFamilyGetCallback cb,
  void *cb_cls);


/**
 * Cancel a GET /private/tokenfamilies/$TOKEN_FAMILY_SLUG request.
 *
 * @param[in] handle handle to cancel
 */
void
TALER_MERCHANT_token_family_get_cancel (
  struct TALER_MERCHANT_TokenFamilyGetHandle *handle);


#endif
