/*
 * =====================================================================================
 *
 *       Filename:  hdm_json.h
 *
 *    Description:  HDM json definitions
 *
 *        Version:  1.0
 *        Created:  09/20/2019 13:16:11 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *        Company:  Samsung Electronics
 *        Copyright (c) 2019 by Samsung Electronics, All rights reserved.
 *
 * =====================================================================================
 */

#ifndef _HDM_JSON_H_
#define _HDM_JSON_H_

/**
 * Includes
 */
#include <stdint.h>
#include <stddef.h>
#include "hdm_defs.h"
#include "hdm_drk.h"

/**
 * JSON Array max elements
 */
#define MAX_ARRAY_SIZE 5

/**
 * @brief
 * json_append_single_char
 * Append a single char in a json.
 *
 * @param[in|out] buffer        - Pointer to the buffer where the json is being built
 * @param[in]     buffer_size   - Max size of the buffer
 * @param[in|out] buffer_offset - Offset of the buffer it is updated inside this function
 * @param[in]     c             - Char to be written to the buffer
 *
 * @return Status code
 */
hdm_return_code_t json_append_single_char(uint8_t *buffer, uint32_t buffer_size, uint32_t *buffer_offset, uint8_t c);

/**
 * @brief
 * json_append_char
 * Append a char field in a json.
 *
 * @param[in|out] buffer        - Pointer to the buffer where the json is being built
 * @param[in]     buffer_size   - Max size of the buffer
 * @param[in|out] buffer_offset - Offset of the buffer it is updated inside this function
 * @param[in]     name          - Name of the json field to be added
 * @param[in]     value         - Char to be written to the buffer
 *
 * @return Status code
 */
hdm_return_code_t json_append_char(uint8_t *buffer, uint32_t buffer_size, uint32_t *buffer_offset, const char *name, char value);

/**
 * @brief
 * json_append_int
 * Append an integer field in a json.
 *
 * @param[in|out] buffer        - Pointer to the buffer where the json is being built
 * @param[in]     buffer_size   - Max size of the buffer
 * @param[in|out] buffer_offset - Offset of the buffer it is updated inside this function
 * @param[in]     name          - Name of the json field to be added
 * @param[in]     value         - Integer value to be added
 *
 * @return Status code
 */
hdm_return_code_t json_append_int(uint8_t *buffer, uint32_t buffer_size, uint32_t *buffer_offset, const char *name, uint32_t value);

/**
 * @brief
 * json_append_string
 * Append an string field in a json.
 *
 * @param[in|out] buffer        - Pointer to the buffer where the json is being built
 * @param[in]     buffer_size   - Max size of the buffer
 * @param[in|out] buffer_offset - Offset of the buffer it is updated inside this function
 * @param[in]     name          - Name of the json field to be added
 * @param[in]     value         - String value to be added
 * @param[in]     format        - Format string for the field, if it is NULL, default format "\"%s\":\"%s\"" is used
 *
 * @return Status code
 */
hdm_return_code_t json_append_string(uint8_t *buffer, uint32_t buffer_size, uint32_t *buffer_offset, const char *name, uint8_t *value, char *format);

/**
 * @brief
 * json_append_certs
 * Append a certificate array in a json.
 *
 * @param[in|out] buffer        - Pointer to the buffer where the json is being built
 * @param[in]     buffer_size   - Max size of the buffer
 * @param[in|out] buffer_offset - Offset of the buffer it is updated inside this function
 * @param[in]     name          - Name of the json field to be added
 * @param[in]     array         - Array of certificates to be added
 * @param[in]     array_size    - Number of elements of the array
 *
 * @return Status code
 */
hdm_return_code_t json_append_certs(uint8_t *buffer, uint32_t buffer_size, uint32_t *buffer_offset, const char *name, drk_cert_chain_t array[], uint8_t num);

#endif
