#ifndef MESSANGERCONTROLLER_H
#define MESSANGERCONTROLLER_H

#include <QObject>
#include <QVBoxLayout>
#include "messangerwidget.h"
#include "connectortoserver.h"

struct MessageOfMessanger
{
    QString text;
    bool flLocal;
    QTime time;
};

class MessangerController : public QObject
{
    Q_OBJECT
public:
    explicit MessangerController(ConnectorToServer* connectorToServer, QObject *parent = nullptr);
    ~MessangerController();

public:
    MessangerWidget* newWidget(QWidget *parent, User* user, QVBoxLayout* boxLayout);
    void deleteWidget(MessangerWidget* msgWdgt);
    void deleteAllWidgets();

    void setUserLocalGUI_ID(int id);

public slots:
    void slot_sendMessage(ClientMessage clientMessage);
    void slot_receiveMessage(ClientMessage clientMessage);

    void slot_reinitMessangers(QList<User> listUsers);

private:
    void showMessageInAllWidgets(ClientMessage clientMessage);

private:
    ConnectorToServer* connectorToServer;
    QList <MessangerWidget*> listWidgets;

    int userLocalGUI_ID;

    QMap <int, QList<MessageOfMessanger>*> mapAlldialogsWithClients;
};

#endif // MESSANGERCONTROLLER_H
