#pragma once
#include <QMap>
#include <QObject>
#include <QTimer>

class EventHandler final : public QObject {
    Q_OBJECT

public:
    explicit EventHandler(QObject *parent = nullptr);

    ~EventHandler() override;

public slots:
    void start();

    void stop();

signals:
    void finished();

private slots:
    void checkAndRestart(); // вызывается по таймеру

private:
    bool m_running = true;
    QMap<QString, QThread *> m_threads;
    QMap<QString, QTimer *> m_timers;
    QTimer *m_checkTimer = nullptr;

    QStringList m_devices;

    void clearAll();

    void startThreadForKey(const QString &key);
};
