#ifndef MULTITHREADSERVER_H
#define MULTITHREADSERVER_H

#include "serverlmswidget.h"
#include "Systems/processingsystem.h"
#include <QObject>

class ProcessingSystem;
class MultiThreadServer : public QTcpServer
{
    Q_OBJECT

public:
    MultiThreadServer(ServerLMSWidget *widget,UpdateController *updateController,ProcessingSystem *processingSystem,
        DataParser *dataParser, qint16 hostPort, QObject *parent = nullptr);


    QMap<int, ClientHandler *> *getClientsMap() const;
    void updateClientList();
    void disableClients();

    bool startServer();
    bool stopServer();
    void blockAutorization()
    {
        stateBlockAutorization = blocked;
    }
    void unBlockAutorization()
    {
        stateBlockAutorization = unblocked;
    }
    EStateBlockAutorization getStateBlockAutorization() const
    {
        return stateBlockAutorization;
    }
signals:
    void sigInitClient(int descriptor, ServerLMSWidget *serverWidget,
                       UpdateController *updateController, DataParser *dataParser);
    void signalStopSendFile();

public slots:
    void slotDisconnectClient(QString peerAddress, QString peerPort);
protected:
    void incomingConnection(qintptr handle) override;

private:
    ServerLMSWidget *serverLmsWidget;
    QMap<int, ClientHandler*> *clientsMap;
    qint16 hostPort;
    ProcessingSystem *processingSystem;
    UpdateController *updateController;
    DataParser *dataParser;

    EStateServer stateServer;
    EStateBlockAutorization stateBlockAutorization;

    void removeClient(int idSocket);
    void addClient(qintptr descriptor, ClientHandler *client);
};

#endif // MULTITHREADSERVER_H
