//
// Created by WJG on 2020-9-10.
//

#ifndef NEWCOSS_DEVICEEXTRA_H
#define NEWCOSS_DEVICEEXTRA_H

#include "json/json.h"
#include "DeviceInfo.h"
#include <mutex>
#include <unordered_map>
#include <unordered_set>

#define CPAD_WIRED_CONTROL_DEV_CLASS "WIRED_DEV"
#define CPAD_WIRED_CONTROL_DEV_TYPE "WiredControl"

#define MUTIL_PANEL_ENABLDE 1

class DeviceExtra {
public:
//    static int setDevice2Home(const Json::Value &device);
//    static int delHomeDevice(const Json::Value &device);
//    static Json::Value getHomeDevice();
//    static int setDevice2Shortcut(const Json::Value &device);
//    static int delShortcutDevice(const Json::Value &device);
//    static Json::Value getShortcutDevice();
    static Json::Value getDefaultLocation();
    static Json::Value getUserDefineLocation();
    static Json::Value getMultiDevice();
    static Json::Value getLocalUserLocation();

    static int updateTempHumi(const Json::Value &value);
    static Json::Value getTempHumi();
//    static void resetBodySensor(std::string dev_id);
//    static void updateBodySensor();
    static void updateBodySensor(std::string dev_id, std::string dev_uuid);
    static void updateDoorSensor(std::string dev_id, std::string dev_uuid, int status);
    static void process_multi_msg(const Json::Value &value);
    static std::vector<std::string> getDevByName(std::string nick_name);
    static void update_device2other_panel();
    static Json::Value getPanelList();
    static int initMultiDevice(const std::string &file_dir);
    static std::string getPanelMgnet(const std::string &panel_sn);
    static void remotePanelName(const Json::Value &value);
    static int localPanelName(const std::string &panel_name);
    static std::string getLocalPanelSN();
    static void updateRoomInfo();

    static void devEventRegister_process(const Json::Value& value);
    static void devActionRegister_process(const Json::Value& value);
    static void devEventTrigger_process(const Json::Value& value);

    static Json::Value getDevInfo(const std::string &device_id);
    static void addNewModuleDevice(std::string dev_id, std::string module);

private:
    static void post_device2other_panel(std::string mgnet);
    static void process_online_msg(const Json::Value &value);
    static void process_offline_msg(const Json::Value &value);
    static void process_room_info(const Json::Value &value);
    static void process_dev_list(const Json::Value &value);
    static void process_dev_status(const Json::Value &value);
    static void update_dev_list(const Json::Value &value);
    static std::string parse_mgnet_info(const Json::Value &value);
    static std::string get_panel_sn();
    static std::string get_panel_name();
    static void process_module_offline(const Json::Value &value);

//    static std::string panel_device_dir;

//    static std::mutex s_map_Mutex;
//    static std::unordered_set<std::string> panel_room_set;
    static std::unordered_map<std::string, std::unordered_set<std::string>> panel_sn_room_map;

    //unordered_map<panel_sn，unordered_set<dev_id>>
    static std::unordered_map<std::string, std::unordered_set<std::string>> panel_sn_devid_map;

    //unordered_map<nick_name，unordered_set<dev_id>>
    static std::unordered_map<std::string, std::unordered_set<std::string>> nickname_devid_map;

    //unordered_map<dev_id, devJson_Info>
    static std::unordered_map<std::string, DeviceInfo> dev_map;
    static std::mutex dev_map_mutex;
    static std::mutex name_dev_map_mutex;

    //unordered_set<nick_name>
//    static std::unordered_set<std::string> nick_name_reged_set;

    //unordered_map<sn, name>
    static std::unordered_map<std::string, std::string> panel_sn_name_map;

    //unordered_map<mgnet, sn>
    static std::unordered_map<std::string, std::string> panel_mgnet_sn_map;

    //unordered_map<sn, mgnet>
    static std::unordered_map<std::string, std::string> panel_sn_mgnet_map;

    //unordered_map<dev_id, devJson_cmdparam>
    static std::unordered_map<std::string, Json::Value> devid_cmdparam_map;

    //unordered_map<dev_id, unordered_set<dev_event>>
    static std::unordered_map<std::string, std::unordered_set<std::string>> devid_event_map;

    //unordered_map<module_id, unordered_set<dev_id>>
    static std::unordered_map<std::string, std::unordered_set<std::string>> moduleid_devid_map;
};

#endif //NEWCOSS_DEVICEEXTRA_H
