#ifndef SENDSYSTEM_H
#define SENDSYSTEM_H

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

#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,QMutex *globalMutex);
    void setClient(Client* client,QTcpSocket *socket);
    void sendMessageBlock(QString message);
    void sendFileBlock(QString path);
    void sendFileBlockByteArray(QByteArray array, PacketType packetType);
    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();
    QByteArray sigSendXMLmessage(QString loginFrom, QString loginTo, QString text, QString userType);
    QByteArray sigSendNotify(QString message);
    QByteArray sigSendVersion();

private:
    Client *client;
    QTcpSocket* socket;
    DataParser* dataParser;
    quint64 fileSize;
    QMutex *mutex;
    QWaitCondition *waitCondition;
    int countSend;
    bool isSendStopped;
    TypeClientAutorization type;
};

#endif // SENDSYSTEM_H
