//
// Created by WJG on 2021-11-9.
//

#ifndef SMARTPANEL_COSS_MULTIPANELSERVICE_H
#define SMARTPANEL_COSS_MULTIPANELSERVICE_H

#include <mgbus/MgBusService.h>
#include <unordered_set>

namespace jedge {
    class MultiPanelService : public MgBusService {

    protected:
        std::unordered_set<std::string> mgbusNodes;
        std::recursive_mutex  mpMutex;

        void preparePattern() override;
        bool eventWatching(MgTriggerWatcher &w, const std::string &k, const qlibc::QData &d);
        bool eventUnwatching(MgTriggerWatcher &w, const std::string &k, const qlibc::QData &d);
        bool OnModuleConnected(MgTriggerWatcher &w, const std::string& k, const qlibc::QData &d);
        bool OnModuleDisconnected(MgTriggerWatcher &w, const std::string& k, const qlibc::QData &d);
        bool cossOnline(qlibc::QData &req, qlibc::QData *resp);
        bool cossOffline(qlibc::QData &req, qlibc::QData *resp);
        bool PostSceneList(qlibc::QData &req, qlibc::QData *resp);
        bool SceneUpdated(qlibc::QData &req, qlibc::QData *resp);

    public:
        explicit MultiPanelService(MgBusHolder &opr, const std::string &srvName, const qlibc::QData &config)
                : MgBusService(opr, srvName, config) {};

        ~MultiPanelService() override = default;

//        void shutdown() override;
//        bool start(const qlibc::QData &config) override;
        void onServiceStart(const qlibc::QData &config) override;

        bool existsSceneById(const std::string &mod, const std::string &id);

        bool moduleOnline(qlibc::QData &req, qlibc::QData *resp);

        bool moduleOffline(qlibc::QData &req, qlibc::QData *resp);
    };
}

#endif //SMARTPANEL_COSS_MULTIPANELSERVICE_H
