#ifndef RECOGNIZESYSTEM_H
#define RECOGNIZESYSTEM_H

#include <QDataStream>
#include <QTcpSocket>
#include <QMutex>

#include <Systems/updatecontroller.h>
#include <Systems/tools.h>
#include <Systems/Parsers/dataparser.h>

#include <Data/Client.h>
#include <Data/PacketType.h>

#include "serverlmswidget.h"

class UpdateController;
class ServerLMSWidget;
class ClientHandler;

class RecognizeSystem : public QObject
{

  Q_OBJECT

public:
    RecognizeSystem(QObject *parent = nullptr);
    void initialize(UpdateController *updateController,DataParser *dataParser,
                    ServerLMSWidget *server,SendSystem *sendSystem, ClientHandler *handler);
    void recognize();
    ~RecognizeSystem();

signals:
    void sigCalculateHash();
    void sigSendToLogger(QString string);
    void sigXmlParser(ClientHandler *clientHandler,QByteArray data);
    void sigChangeVersion(QString versionName);
    void sigDeleteVersion(QString versionName);
    void sigCopyVersion(QString versionName,QString newVersionName,QString author);

private:
    UpdateController *updateController;
    SendSystem *sendSystem;
    DataParser *dataParser;
    ServerLMSWidget *server;
    QString command;
    PacketType packetType;
    QString filePath;
    ClientHandler *clientHandler;
    QMutex *mutex;

    QTcpSocket *socket;

    QByteArray tmpBlock;

    qint64 sizeReceiveData;
    qint64 fileSize;
    int countSend;
    bool isPackageTypeInited;

    void packetTypeInit(PacketType packet,Client *client);
    //void packetTypeInit(PacketType type);

    bool checkIsChangeable();    
};
#endif // RECOGNIZESYSTEM_H
