#ifndef __CONFIG_H__
#define __CONFIG_H__

#ifdef __cplusplus
#ifndef BEGIN_DECLS
#define BEGIN_DECLS extern "C" {
#endif
#ifndef END_DECLS
#define END_DECLS }
#endif
#else
#ifndef BEGIN_DECLS
#define BEGIN_DECLS
#endif
#ifndef END_DECLS
#define END_DECLS
#endif
#endif

BEGIN_DECLS

#if defined(_WIN32) && defined(UNICODE)
#include <wchar.h>
#endif

#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>
#include <pthread.h>
#include <ctype.h>
#include <limits.h>

#include "Common.h"
#include "SecureCodingUtil.h"
#include "StringUtil.h"

#define MAX_CONFIG_NUMBER           1000

#define CONF_ERR_SUCCESS            0
#define CONF_ERR_FILEOPEN           -1
#define CONF_ERR_MEM                -2
#define CONF_ERR_TOKEN_ERR          -3
#define CONF_ERR_NOT_FOUND          -4
#define CONF_ERR_NULL_PARAMETER     -5
#define CONF_ERR_ZERO_LENGTH        -6

#define CONF_KEY_SEPERATOR          '='
#define CONF_LIST_SEPERATOR         ','

#ifdef _WIN32
#define CONF_FILE_PATH              "..\\..\\config"
#else
#define CONF_FILE_PATH              "../config"
#endif
#define CONF_FILE_EXT               ".conf"

struct CONFIG_VALUE
{
    char szKey[MAX_STRING_SIZE + 1];
    char szValue[MAX_STRING_SIZE + 1];
    
};

struct VALUE_STRING_PAIR_INFO
{
    int nValue;
    char szValueString[MAX_STRING_SIZE + 1];
};

int ReadConfigFile(int bInitialize, const char *szFileName);
int GetConfigValue(const char *szKey, char *szValue, int nValueLength);
int ParsingYESNO(const char *pszValue, const int nInputValueLength, int *pbYESNOValue);
int MappingIntToString(const struct VALUE_STRING_PAIR_INFO *pPairInfo, int nPairInfoCount, int nValue, char *pStringValue, int nStringValue);
int MappingStringToInt(const char *szStringFlags, int nInputTagStringLength, const struct VALUE_STRING_PAIR_INFO *pFlagInfo, int nMaxFlagInfoSize, int *pnValue);
int ParsingFlagString(const char *szStringFlags, int nInputTagStringLength, const struct VALUE_STRING_PAIR_INFO *pFlagInfo, int nMaxFlagInfoSize, int *pnValue);

char *GetPairString(const struct VALUE_STRING_PAIR_INFO *pPairInfo, int nPairInfoCount, int nValue);
int GetPairValue(const struct VALUE_STRING_PAIR_INFO *pPairInfo, int nPairInfoCount, char *pStringValue);

END_DECLS

#endif
