#ifndef WEBSERVERCONTROL_H
#define WEBSERVERCONTROL_H

#include <QObject>

#include <vector>
#include <map>

#include "platformobject.h"
#include "parametersetting.h"

using namespace std;



QT_FORWARD_DECLARE_CLASS(QWebSocketServer)
	QT_FORWARD_DECLARE_CLASS(QWebSocket)
	QT_FORWARD_DECLARE_CLASS(QString)

class WebServerControl : public QObject
{
	Q_OBJECT

public:

private:
	static WebServerControl* m_pWebServerControl;

public:
	static WebServerControl*GetInstance();
	static void FreeInstance();

	explicit WebServerControl(quint16 port, QObject *parent = nullptr);
	WebServerControl(QObject *parent = nullptr);
	~WebServerControl();

	void InitQWebSocketServer(quint16 port );

	private slots:
		void onNewConnection();
		void processMessage(const QByteArray &message);
		void socketDisconnected();

		void processMessageText(const QString &message);

		void InitHeadCooko();

		void Parse_Now_Json(const QByteArray &arrayjson);

		void InsertMapPlatObject(QString strType,const DataPlatform &item);
		
public:	 
		void CalcAver();
		void CalcdeviationCompensation();
		void CalculateDeviationPercentage();
		void ParseJson(const QByteArray &arrayjson);


private:
	QWebSocketServer *m_pWebSocketServer;
	vector<QWebSocket *> m_vClients;
	PlatformObject* m_pBinancePlatformObject;
	map<QString,PlatformObject*> m_mPlatformObjects;
	ParameterSetting m_ParameterSetting;
};

#endif // WEBSERVERCONTROL_H
