#ifndef SENDSYSTEM_H
#define SENDSYSTEM_H

#include <QObject>
#include <QString>
#include <QtNetwork>

#include <Systems/Parsers/dataparser.h>
#include <Systems/tools.h>
#include <Data/Client.h>
#include <Data/PacketType.h>

class DataParser;
class FileData;

class SendSystem : public QObject
{

    Q_OBJECT
public:
    explicit SendSystem(QObject* parent = nullptr);

    void initialize(DataParser* dataParser,Logger *logger);
    void setClient(Client* client,QTcpSocket *socket);
    void sendMessageBlock(QString message);
    void sendFileBlock(QString path);
    void sendFileBlockWithRename(QString path,QString newName);
    void sendFolderBlock(QString path);
    void sendDeleteBlock(QString path);
    void sendPacketType(PacketType packet);
    void sendHello();
    void sendNotify(QString notify);
    void sendStop();
    void sendXmlAnswer(QByteArray array, PacketType packetType = PacketType::TYPE_XMLANSWER);
    void sendNeedUpdate(bool flag,quint64 size,quint64 fileCount,quint64 deleteCount);
    void updateFiles(QList<FileData> fileSendList, QList<FileData> deleteList);
    bool socketFlush();

    bool getIsSendStopped() const;

    ~SendSystem();


public slots:
    void socketWrite(QByteArray array);
    void socketClose();
    void sendVersion();

signals:
    void sigLoadHash();
    void sigSendToLogger(QString message);
    QByteArray sigSendXMLmessage(QString message, QString login = "");
    QByteArray sigSendNotify(QString message);
    QByteArray sigSendVersion();

private:
    Client *client;
    QTcpSocket* socket;
    DataParser* dataParser;
    Logger *logger;
    QMutex *mutex;
    quint64 fileSize;
    int countSend;
    bool isSendStopped;
    bool isUnity;


};

#endif // SENDSYSTEM_H
