/*
 * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Created in Samsung Ukraine R&D Center (SRK) under a contract between
 * LLC "Samsung Electronics Ukraine Company" (Kiev, Ukraine)
 * and "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
 */

/**
 * @file TigerJson.h
 * @brief Implements JSON functionality.
 * @author Victor Kopp <v.kopp@samsung.com>
 * @date Created Jun 12, 2017
 */

#ifndef SRC_TIGERJSON_H_
#define SRC_TIGERJSON_H_

#include <stdint.h>
#include <stddef.h>

#include "TzwCommon.h"

/**
 * @brief Declaration of structure to hold (incomplete) JSON data
 */
struct __JsonObject;

/**
 * @brief Opaque JSON object handle
 */
typedef struct __JsonObject* JsonObject_t;

/**
 * @brief Creates JSON object.
 * @param[in] obj - JSON object.
 */
void jsonCreate(JsonObject_t *obj);

/**
 * @brief Releases JSON object.
 * @param[in] obj - JSON object.
 */
void jsonRelease(JsonObject_t obj);

/**
 * @brief Writes specified string to JSON object.
 * @param[in] obj - JSON object.
 * @param[in] str - input string.
 * @return status of the operation, e.g. TEE_SUCCESS on success.
 */
TEE_Result jsonWriteRawString(JsonObject_t obj, const char* str);

/**
 * @brief Writes specified key and uint32_t-type integer to JSON object.
 * @param[in] obj - JSON object.
 * @param[in] key - the key.
 * @param[in] val - the integer.
 * @return status of the operation, e.g. TEE_SUCCESS on success.
 */
TEE_Result jsonWriteKeyUint32(JsonObject_t obj, const char* key, const uint32_t val);

/**
 * @brief Writes specified key and uint32_t-type integer as a string (with quotes) to JSON object.
 * @param[in] obj - JSON object.
 * @param[in] key - the key.
 * @param[in] val - the integer.
 * @return status of the operation, e.g. TEE_SUCCESS on success.
 */
TEE_Result jsonWriteKeyUint32AsStr(JsonObject_t obj, const char* key, const uint32_t val);

/**
 * @brief Writes specified key and uint64_t-type integer to JSON object.
 * @param[in] obj - JSON object.
 * @param[in] key - the key.
 * @param[in] val - the integer.
 * @return status of the operation, e.g. TEE_SUCCESS on success.
 */
TEE_Result jsonWriteKeyUint64(JsonObject_t obj, const char* key, const uint64_t val);

/**
 * @brief Writes specified key and uint64_t-type integer as a string (with quotes) to JSON object.
 * @param[in] obj - JSON object.
 * @param[in] key - the key.
 * @param[in] val - the integer.
 * @return status of the operation, e.g. TEE_SUCCESS on success.
 */
TEE_Result jsonWriteKeyUint64AsStr(JsonObject_t obj, const char* key, const uint64_t val);

/**
 * @brief Writes specified key and string to JSON object.
 * @param[in] obj - JSON object.
 * @param[in] key - the key.
 * @param[in] str - the string.
 * @return status of the operation, e.g. TEE_SUCCESS on success.
 */
TEE_Result jsonWriteKeyString(JsonObject_t obj, const char* key, const char* str);

/**
 * @brief Writes comma to JSON object.
 * @param[in] obj - JSON object.
 * @return status of the operation, e.g. TEE_SUCCESS on success.
 */
TEE_Result jsonWriteComma(JsonObject_t obj);

/**
 * @brief Writes open brace to JSON object.
 * @param[in] obj - JSON object.
 * @return status of the operation, e.g. TEE_SUCCESS on success.
 */
TEE_Result jsonOpenBrace(JsonObject_t obj);

/**
 * @brief Writes close brace to JSON object.
 * @param[in] obj - JSON object.
 * @return status of the operation, e.g. TEE_SUCCESS on success.
 */
TEE_Result jsonCloseBrace(JsonObject_t obj);

/**
 * @brief Writes specified key and buffer to JSON object.
 * @param[in] obj - JSON object.
 * @param[in] key - the key.
 * @param[in] buffer - the buffer.
 * @param[in] bufferSize - buffer size.
 * @return status of the operation, e.g. TEE_SUCCESS on success.
 */
TEE_Result jsonWriteKeyBuffer(JsonObject_t obj, const char* key,
                              const uint8_t* buffer, const uint32_t bufferSize);

/**
 * @brief Gets current string from JSON object.
 * @param[in] obj - JSON object.
 * @return current string.
 */
const char* jsonGetPlain(const JsonObject_t obj);

/**
 * @brief Gets current string length from JSON object.
 * @param[in] obj - JSON object.
 * @return current string length.
 */
uint32_t jsonGetLength(const JsonObject_t obj);

#endif /* SRC_TIGERJSON_H_ */
