/********************************* (C) РОТЕК ***********************************
 * @module  web_params_api
 * @file    web_params_api.h
 * @version 1.0.0
 * @date    XX.XX.XXXX
 * $brief   template
 *******************************************************************************
 * @history     Version  Author         Comment
 * XX.XX.XXXX   1.0.0    Telenkov D.A.  First release.
 *******************************************************************************
 */

/* Define to prevent recursive  ----------------------------------------------*/
#ifndef WEB_PARAMS_API_H
#define WEB_PARAMS_API_H

#include "stdbool.h"

#define JSON_ADD_TAG(tag, get_param, cjson_param) \
  do { \
    memset(str, 0, sizeof(str)); \
    get_param(str, &len); \
    if (strncmp(tag, "tn_enabled", sizeof(tag)) == 0  \
        || strncmp(tag, "ssh_enabled", sizeof(tag)) == 0 \
        || strncmp(tag, "dhcp", sizeof(tag)) == 0 \
        || strncmp(tag, "swauth", sizeof(tag)) == 0 \
        || strncmp(tag, "ups_max_power", sizeof(tag)) == 0 \
        || strncmp(tag, "syslog_enable", sizeof(tag)) == 0 \
        || strncmp(tag, "rs_enabled", sizeof(tag)) == 0) { \
      cJSON_AddNumberToObject(cjson_param, tag, atoi(str)); \
    } else if (strncmp(tag, "pgw_en", sizeof(tag)) == 0 ) { \
      if (strncmp(str, "true", 4) == 0 ) { \
        cJSON_AddBoolToObject(cjson_param, tag, true); \
      } else { \
        cJSON_AddBoolToObject(cjson_param, tag, false); \
      }\
    } else { \
      cJSON_AddStringToObject(cjson_param, tag, str); \
    } \
  } while (0);

#define JSON_SET_PARAM(tag, set_param, buf) \
    do { \
        memset(value, 0, sizeof(value)); \
        memset(str, 0, sizeof(str)); \
        if (GetParamValue(buf, tag, value, &valueLen)) { \
            url_decode(str, sizeof(str), value); \
            set_param(str); \
        } else { \
          if (strncmp(tag, "tn_enabled", sizeof(tag)) == 0  \
              || strncmp(tag, "ssh_enabled", sizeof(tag)) == 0 \
              || strncmp(tag, "dhcp", sizeof(tag)) == 0 \
              || strncmp(tag, "swauth", sizeof(tag)) == 0 \
              || strncmp(tag, "pgw_en", sizeof(tag)) == 0 \
              || strncmp(tag, "syslog_enable", sizeof(tag)) == 0 \
              || strncmp(tag, "rs_enabled", sizeof(tag)) == 0) { \
            set_param(value); \
          } \
        } \
    } while (0);

/**
  * @brief  Заполнение JSON строки параметров
  */
char *HTTP_GetParamsPage(uint32_t reqNum, char *bufIn, char *bufOut, uint16_t lenBufIn, uint16_t *lenBufOut);
  
/**
  * @brief  Возвращяет строку с настройками на второй странице
  */
char *HTTP_GetSettingsPage(uint32_t reqNum, char *bufIn, char *bufOut, uint16_t lenBufIn, uint16_t *lenBufOut);

#ifdef NOTIFICATION_CONTROL_ENABLE
/**
  * @brief  Возвращяет строку с настройками уведомлений (есть/нет отправка)
  * @retval None
  */
char *HTTP_GetTrapAccess(char *params, uint16_t len_params, char *buf, uint16_t *len_out);
#endif

/**
  * @brief  Возвращяет строку с информацией об устройстве
  */
char *HTTP_GetInfo(uint32_t reqNum, char *bufIn, char *bufOut, uint16_t lenBufIn, uint16_t *lenBufOut);

void HTTP_GetHistoryPage(char* buf, uint32_t pageNumber);

void HTTP_GetUpsHistoryPage(char* buf, uint32_t pageNumber);

/**
  * @brief  Возвращает uptime, freq, dutycicle
  */
void HTTP_GetProgonParams(char *buf);

/**
  * @brief  Сброс настроек
  */
void HTTP_ResetSettings(void);
	
/**
  * @brief  Сброс настроек
  */
void HTTP_SaveSettings(void);

/**
  * @brief  Перезагрузка контроллера
  */
char *HTTP_Reboot(uint32_t reqNum, char *bufIn, char *bufOut, uint16_t lenBufIn, uint16_t *lenBufOut);

/**
  * @brief  
  */
void HTTP_StartResetTask(bool fBootMode);

/**
  * @brief  
  */
void vTaskReboot(void * pvParameters);

#endif /* #ifndef WEB_PARAMS_API_H */

/********************************* (C) РОТЕК **********************************/
