#ifndef TCI_DATA_H
#define TCI_DATA_H

#include "Shared/QualifiedName.h"
#include "Shared/BinaryString.h"
#include <wchar.h>

typedef void* Value;
typedef void* Type;
typedef void* TciValueTemplate;
typedef void* TciNonValueTemplate;
typedef void* TciValueList;

typedef Value VerdictValue;

typedef char* String;
typedef unsigned char Boolean;

typedef QualifiedName TciModuleIdType;
typedef QualifiedName TciTestCaseIdType;
typedef QualifiedName TciBehaviourIdType;
typedef QualifiedName TciModuleParameterIdType;

typedef struct TciTestCaseIdListType
{
	long int length;
	QualifiedName *idList;
} TciTestCaseIdListType;

typedef TciTestCaseIdListType TciModuleIdListType;

typedef enum
{
	TCI_ADDRESS_TYPE = 0,
	TCI_ANYTYPE_TYPE = 1,
	TCI_BITSTRING_TYPE = 2,
	TCI_BOOLEAN_TYPE = 3,
	TCI_CHAR_TYPE = 4,
	TCI_CHARSTRING_TYPE = 5,
	TCI_COMPONENT_TYPE = 6,
	TCI_ENUMERATED_TYPE = 7,
	TCI_FLOAT_TYPE = 8,
	TCI_HEXSTRING_TYPE = 9,
	TCI_INTEGER_TYPE = 10,
	TCI_OBJID_TYPE = 11,
	TCI_OCTETSTRING_TYPE = 12,
	TCI_RECORD_TYPE = 13,
	TCI_RECORD_OF_TYPE = 14,
	TCI_ARRAY_TYPE = 15,
	TCI_SET_TYPE = 16,
	TCI_SET_OF_TYPE = 17,
	TCI_UNION_TYPE = 18,
	TCI_UNIVERSAL_CHAR_TYPE = 19,
	TCI_UNIVERSAL_CHARSTRING_TYPE = 20,
	TCI_VERDICT_TYPE = 21
} TciTypeClass;

typedef struct TciCharStringValue
{
	unsigned long int length;
	char* string;
} TciCharStringValue;

typedef unsigned char TciUCValueOld[4];//should not be used in TCI, only for TC<->CD callback interface

typedef struct TciUCStringValue
{
	unsigned long int length;
	wchar_t * string;
} TciUCStringValue;

typedef struct TciObjidElemValue
{
	char* elem_as_ascii;
	long int elem_as_number;
	void* aux;
} TciObjidElemValue;

typedef struct TciObjidValue
{
	unsigned long int length;
	TciObjidElemValue* elements;
} TciObjidValue;

typedef enum
{
	TCI_IN_PAR = 0,
	TCI_INOUT_PAR = 1,
	TCI_OUT_PAR = 2
} TciParameterPassingModeType;

typedef struct TciParameterTypeType
{
	Type parameterType;
	TciParameterPassingModeType mode;
} TciParameterTypeType;

typedef struct TciParameterTypeListType
{
	long int length;
	TciParameterTypeType *parList;
} TciParameterTypeListType;

typedef struct TciParameterType
{
	String parName;
	TciParameterPassingModeType	parPassMode;
	Value parValue;
} TciParameterType;

typedef struct TciParameterListType
{
	long int length;
	TciParameterType *parList;
} TciParameterListType;

typedef struct TciParameterListType32
{
	int32_t length;
	TciParameterType *parList;
} TciParameterListType32;

typedef struct TciModuleParameterType
{
	String parName;
	Value defaultValue;
} TciModuleParameterType;

typedef struct TciModuleParameterListType
{
	long int length;
	TciModuleParameterType *modParList;
} TciModuleParameterListType;

typedef int TciStatus;//for TL interface compatibility
/*
typedef enum
{
	TCI_OK = 0,
	TCI_ERROR = 1
} TciStatus;
*/

extern const int TCI_OK;
extern const int TCI_ERROR;

typedef struct TciValueDifference
{
	Value val;
	TciValueTemplate tmpl;
	String desc;
} TciValueDifference;

typedef struct TciValueDifferenceList
{
	long int length;
	TciValueDifference* diffList;
} TciValueDifferenceList;

typedef struct TciValueDifferenceList32
{
	int32_t length;
	TciValueDifference* diffList;
} TciValueDifferenceList32;

typedef int ComponentStatus;//for TL interface compatibility
/*
typedef enum
{
	INACTIVE_C,
	RUNNING_C,
	STOPPED_C,
	KILLED_C
} ComponentStatus;
*/
extern const int TCI_INACTIVE_C;
extern const int TCI_RUNNING_C;
extern const int TCI_STOPPED_C;
extern const int TCI_KILLED_C;
extern const int TCI_NULL_C;

typedef int TimerStatus;//for TL interface compatibility
/*
typedef enum
{
	RUNNING_T,
	INACTIVE_T,
	EXPIRED_T
} TimerStatus;
*/

extern const int TCI_RUNNING_T;
extern const int TCI_INACTIVE_T;
extern const int TCI_EXPIRED_T;
extern const int TCI_NULL_T;

typedef enum
{
	STARTED_P,
	STOPPED_P,
	HALTED_P
} PortStatus;

extern const int TCI_VERDICT_NONE;
extern const int TCI_VERDICT_PASS;
extern const int TCI_VERDICT_INCONC;
extern const int TCI_VERDICT_FAIL;
extern const int TCI_VERDICT_ERROR;
extern const int TCI_VERDICT_USER_ERROR;

//Additional data
#define ADDITIONAL_DATA_VER 1
typedef struct AdditionalDataV1
{
	int32_t nBitPosition;
} AdditionalDataV1;

//Helper functions
void clearBinaryString(BinaryString * binaryString);
void siWriteToTCLog(const wchar_t * message);
Value siInternalDecode(const BinaryString * pBS, const Type decodingHypothesis);
BinaryString siInternalEncode(const Value value);
int getBinaryStringStartingPosition(const BinaryString *bs);
void setBinaryStringStartingPosition(BinaryString *bs, int nBitPosition);

#endif
