#pragma once
#include "DCOMHelper.h"
#include <atlsafe.h>
#include "ConstsAndTypeDefs.h"

typedef char* ChannelID;
typedef ChannelID* ChannelIdList;

class DSXInstance;
// Save index as VARIANT 

class ChannelInstance {
public:
	std::string channelIndex;
	CComSafeArray<int32_t> channelIndexVariant;
	int connectionType;
	bool chIsAsync;
	bool chIsSingleValue;
	std::string chName;
	std::string chUnit;
	double chExpectedAsyncRate;
	double chSampleRate;
	bool chIsControlCh;
	int instanceId;
	DSXInstance* instance;
	bool transferred;
	DSX_DATA_TYPE DataType;

	ChannelInstance() : chSampleRate(-1), connectionType(-1), chIsAsync(false), channelIndex(""), chName("") {}
	virtual int dsconChannelSetTransferred(bool transferred);

	virtual int dsconGetSampleRate(double* sampleRate);
	virtual int dsconGetChannelType(int* chType);
	virtual int dsconIsChannelControl(bool* result);
	virtual int dsconGetChUnit(char* resultUnit, size_t len);

	virtual int dsconChannelReadScalarData(double** data, double** timestamps, size_t* count);
	virtual int dsconChannelReadScalarData_2(double* data, double* timestamps, size_t* count);
	virtual int dsconChannelGetName(char* name, size_t len);
	virtual int dsconControlChannelWriteValue(double value, double time);
	virtual int dsconChannelReset();
	virtual int dsconChannelStart();
};

// return prop if channel is control channel
// 
class DSXInstance {
public:
	bool connected;
	int connectionType;

	IDispatch* DCOMMaster;
	VARIANT* DCOMconnections;
	int NumDCOMConnections;
	int currentIndex;
	int numberOfIds;

	std::vector<ChannelInstance> vectorChannelInstance;

	std::vector<std::vector<int>> enumaratedChsInt;
	std::vector<std::string> enumaratedChsStr;
	std::vector<std::vector<char>> enumaratedChsStrOld;
	int iteratorIndex;

	DSXInstance() : connected(false), connectionType(0), currentIndex(0) {};

	virtual int dsconConnect(char* connectionString);
	virtual int dsconDisconnect();
	virtual int dsconGetChannelCount(size_t* count);
	virtual int dsconSetAppWindowVisible(bool visible);
	virtual int dsconLoadSetup(char* fileName);
	virtual int dsconIsInAqusition(bool* value);
	virtual int dsconStartMeasurement();
	virtual int dsconStopMeasurement();
	virtual int dsconBeginRead(double* startTime, double* endTime);
	virtual int dsconEnumerateChannels(ChannelIdList* channelIdList, size_t* count);
	virtual ChannelInstance* CreateChannelInstance(DSXInstance* handle, ChannelID id);
	virtual ChannelInstance* CreateChannelInstanceByName(char* chName);

	virtual int dsconFreeEnumerateChannels(ChannelIdList* channelIdList);

	virtual int InitChannelIdEnum();
	virtual int GetNextChannelIdSize(int* size);
	virtual int GetNextChannelId(ChannelID id);
};


