#ifndef TCPSERVER_CLIENT_H
#define TCPSERVER_CLIENT_H

#include <QTcpSocket>
#include <QJsonDocument>
#include <QJsonArray>

#include "service.h"

class TcpClient : public Service
{
	Q_OBJECT

	QTcpSocket* socket;
	client_state_t state = STATE_IDLE;
	long long recievebytes = 0;
	QByteArray buffer;

public slots:
	virtual void itemUpdated(ItemUpdateRequest update) override;
	virtual void sensorEvent(Sensor sensor, sensor_update_type_t type) override;

public:
	TcpClient(QObject* parent = nullptr);
	~TcpClient();
	virtual bool launch(const QHostAddress &address = QHostAddress::Any, quint16 port = 0) override;
	virtual void sendJson(const QJsonObject& json) override;

protected:
	virtual void processIncomeingJson(const QByteArray& jsonbytes) override;

private slots:
	void socketReadyRead();
	void processComand(const QByteArray& command);
};

#endif // TCPSERVER_CLIENT_H
