#include "Errors.h"
#include "NDTSError.h"

typedef struct 
{
	SCO_ReturnCode code ;
	char *pCodeString ;
} SCO_Error ;

SCO_Error SCO_ApiErrors[] = 
{
	{SCO_OK,																"OK"},
	{SCO_PropertyOutOfRange,												"A property index is outside the range of 0..SCO_ReturnNumberOfPropertyIndices() -1"},
	{SCO_PropertyNoLongerUsed,												"A property index is no longer in use"},
	{SCO_PropertyValueOutOfRange,											"A property value has been clamped"},
	{SCO_PropertyMinUpdated,												"A property minimum value has changed"},
	{SCO_PropertyMaxUpdated,												"A property maximum value has changed"},
	{SCO_propertyFlagUpdated,												"A property type has changed"},
	{SCO_InvalidGateIndex,													"The gate index is not valid"},
	{SCO_EnumStringNotFound,												"There is no enum string for this property index / enum number"},
	{SCO_PropertySetWhenScanning,											"A property can only be set when isScanning is False"},
	{SCO_PropertyIsReadOnly,												"The property is read only"},
	{SCO_GeneralError,														"An error has been logged from the common SDK"},
	{SCO_NotInitialised,													"This function should not be called before SCO_Initialise()"},

	{SCO_LastError,														"Unknown"}
} ;


SCO_API const char * CALL_CONV SCO_GetCodeString(int errorCode)
{
	int i = 0 ;

	while (SCO_ApiErrors[i].code != errorCode && SCO_ApiErrors[i].code != SCO_LastError)
		i++ ;

	return SCO_ApiErrors[i].pCodeString ;
}

void SCO_HandleSCOError(SCO_ReturnCode errorCode) 
{
	NDTS_HandleError(errorCode) ;
}

void SCO_HandleSCOErrorWithLogLevel(SCO_ReturnCode errorCode,  NDTS_LogLevel logLevel) 
{
	NDTS_HandleErrorWithLogLevel(errorCode, logLevel) ;
}

// The SCO error log combines the error logs from the other DLL's
SCO_API int SCO_ReturnNumberOfErrorLogLines()
{
	return NDTS_ReturnNumberOfErrorLogLines() ;
}

SCO_API NDTS_Boolean SCO_GetErrorLogLine(int lineNumber, char *pMessageBuffer, int numberOfBytesInMessageBuffer)
{
	return NDTS_GetErrorLogLine(lineNumber, pMessageBuffer, numberOfBytesInMessageBuffer) ;
}


SCO_API NDTS_Boolean SCO_ClearErrorLog() 
{
	return NDTS_ClearErrorLog() ;
}
