/*
     This file is part of GNUnet.
     Copyright (C) 2026 Taler Systems SA

     Paivana 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.

     Paivana 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 Paivana; see the file COPYING.  If not,
     write to the Free Software Foundation, Inc., 51 Franklin
     Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

/**
 * @author Christian Grothoff
 * @file paivana-httpd_templates.h
 * @brief functions to work with merchant backend templates
 */
#ifndef PAIVANA_HTTPD_TEMPLATES_H
#define PAIVANA_HTTPD_TEMPLATES_H

#include <microhttpd.h>
#include <gnunet/gnunet_util_lib.h>


/**
 * Load the templates from the merchant backend.  Calls
 * PAIVANA_HTTPD_serve_requests() upon completion if successful,
 * otherwise may initiate shutdown.
 */
void
PAIVANA_HTTPD_load_templates (void);


/**
 * Redirect to the paywall page for the given @a website.
 *
 * @param connection request to search paywall response for
 * @param website site to look for paywall templates for
 * @return #GNUNET_OK if a response was queued -- the redirect to the
 *         paywall, but also the 414 for an over-long @a website and
 *         the 400 for a request we cannot build a base URL for,
 *         #GNUNET_NO to close the connection with error,
 *         #GNUNET_SYSERR if there is no paywall for @a website
 */
enum GNUNET_GenericReturnValue
PAIVANA_HTTPD_search_templates (struct MHD_Connection *connection,
                                const char *website);


/**
 * Return the paywall page for the given @a template.
 *
 * @param connection request to search paywall response for
 * @param template template to return paywall page for
 * @return MHD status code
 */
enum MHD_Result
PAIVANA_HTTPD_return_template (struct MHD_Connection *connection,
                               const char *template);


/**
 * Unload all of the template state.
 */
void
PAIVANA_HTTPD_unload_templates (void);

#endif
