#ifndef UPDATECONTROLLER_H
#define UPDATECONTROLLER_H


#include <QString>
#include <QObject>
#include <QCryptographicHash>
#include <QDirIterator>
#include <QDebug>
#include <QDataStream>
#include <QMutex>
#include "Systems/dataparser.h"
#include "typesDataServerClient.h"

class TCPServer;
class SendSystem;
class DataParser;
class ClientHandler;

class UpdateController : public QObject
{
    Q_OBJECT

public:

    explicit UpdateController(QObject *parent = 0);
    void initialize(TCPServer* server,DataParser *dataParser);
    void compareFiles(ClientHandler* handler, QByteArray array);
    void showHash();
    void calculateHash();
    QByteArray getLocalHash();

    QList<FileData> getFileSendList() const;
    QList<FileData> getClientDataList() const;

    ~UpdateController();

signals:
    void sigLogMessage(QString message);

private:
    QList<FileData> clientDataList;
    QList<FileData> serverDataList;
    QList<FileData> folderDataList;

    QList<FileData> fileSendList;
    QList<FileData> fileDeleteList;

    QString sourcePath;
    TCPServer *server;
    DataParser *dataParser;
    quint64 sizeToSend;
    QMutex *mutex;

    QString getCommands();
    bool checkNeedUpdate(ClientHandler* handler);
    void setLocalFileData(QList<FileData> dataList);
    void calculateSize();
    void saveHash();
    void loadHash();
    void CalculateSizeToSend(QList<FileData> diffList);
};

#endif // UPDATECONTROLLER_H
