/*
 * kk_handleDeviceInfo.h
 *
 *  Created on: 2020年11月17日
 *      Author: hj
 */

#ifndef KK_HANDLEDEVICEINFO_H_
#define KK_HANDLEDEVICEINFO_H_

#include <sys/types.h>
#include "json/value.h"
#include <vector>
#include <set>
#include <string>

using namespace std;

//第1期接入设备   //产品ID 2021.3.35
#define ZeroFire1ChanChopinSwitch_PID 		"1603bcc0b8a103e91603bcc0b8a16001" 	//肖邦-一路灯控
#define ZeroFire2ChanChopinSwitch_PID 		"1603bec0b8a203e91603bec0b8a28001" 	//肖邦-二路灯控
#define ZeroFire3ChanChopinSwitch_PID 		"1603bec0b8a303e91603bec0b8a32a01" 	//肖邦-三路灯控
//第2期接入设备   //临时定义 2020.11.18
// #define	Chopin1CurtainSwitch_PID			"410100" 	//肖邦-一路窗帘
// #define	Chopin2CurtainSwitch_PID			"410200" 	//肖邦-二路窗帘
// #define ZeroFire2ChanModularSwitch_PID 		"400201"  	//两路智能开关模块Z3S(KONKE)
// #define Chopin1ChanScenePanel_PID 			"420100" 	//肖邦-零火一路情景面板
// #define WaterSensor_PID 		            "440500" 	//邦德-水浸传感器
// #define	BodyMotionSensor_PID				"440200"	//KIT-人体传感器
// #define	DoorContact_PID						"440100" 	//邦德-门磁传感器
// #define SOSButton_PID 		                "440400" 	//邦德-sos紧急呼叫
// #define SoundLightAlarm_PID 		        "440300" 	//邦德-声光报警器
// #define DimmerLightPanel_PID 				"430100" 	//肖邦-调光面板
// #define WaterHeating_PID 					"450300" 	//肖邦-水地暖
// #define ElectricHeating_PID 				"450301" 	//肖邦-电地暖
// #define FanCoilPanel_PID 					"450100" 	//肖邦-风机盘管面板
// #define AirConditioner_PID 	  		        "450101" 	//肖邦-中央空调线控器（大金）
// #define ChopinFreshAir_PID 					"450200" 	//肖邦-新风控制面板
// #define DAIKINCentralACgw_PID 				"450400" 	//中央空调网关
// #define DAIKINCentralACindoor_PID 			"450401" 	//中央空调内机(等待调整)

class kk_handleDeviceInfo{
public:				////////先建立
	class KKDevmapinfo {
			public:
				string dev_model_id;
				// string dev_type;
				string sn;
				string mac;
			};
public:
	class KKChannelDev {
		public:
			string operateId;
			string nodeId;
			string channel;
			string devname;
			string devroomid;
		};

	class HwSubDev {
	public:
		string dev_model_id; //产品ID ProdID
		// string dev_type;	 //产品类型
		string operatetype;  //设备的operate_type类型
		string devTypeId;
		string model;
		string sn;			 //dev_id
		string mac;			 //设备的mac
		bool online;
		map<string,KKChannelDev*> channelDevs;

	};

	class HwSwitch:public KKChannelDev { //只有开关的设备 开关灯控/插座/开关模块
		public:
			bool on;
	};
	class HwCurtain:public KKChannelDev { //窗帘面板
		public:
		string mode;
	};
	class HwScenePanel:public KKChannelDev{//情景面版 （肖邦情景面板-长供电）
		public:
		string num;        //情景按钮编号
		string leftBattery;//剩余电量百分比
	};

	class HwSensor:public KKChannelDev { //传感器设备 ：邦德-门磁 KIT-人体 邦德-声光 邦德-水浸 邦德-紧急按钮
		public:
			string alarm;  //触发与否
			string leftbattery; //剩余电量百分比
			string sound;	//报警器音量
			string power_style;	//供电方式。0：市电，1：电池；
		};

	class HwDimmerLightPanel:public KKChannelDev { //肖邦-调光灯面板
	public:
		bool on;
		string brightness;
		string time;
	};

	class HwWaterElectricHeating:public KKChannelDev { //肖邦-水地暖 肖邦-电地暖
		public:
			bool on;
			string mode;
			bool childLockSwitch;
			string current; //当前温度
			string target; //目标温度  （20.0—30.0  +_0.5）
		};

	class HwChopinFreshAir:public KKChannelDev { //肖邦-新风控制面板
	public:
		bool on;
		int mode;
		string fan;
		bool childLockSwitch;
		string current; //当前温度
		bool lightSwitch;
		int downtime;
		int totalTime;
		int leftTime;
		bool reset;
	};

	class HwConditionerPanel:public KKChannelDev { //肖邦-风机盘管面板  //肖邦-中央空调线控器（大金）
	public:
		bool on;
		string mode;
		string fan;
		bool childLockSwitch; //童锁开关
		string current; //当前温度
		string target; //目标温度
		int downtime;
		bool enable;
	};

	class HwCentralAcgw:public KKChannelDev {//中央空调网关(四期调整)
		public:
			int num; //内机数目
	};

	class HwCentralAcindoor:public KKChannelDev {//中央空调内机(四期调整)
		public:
			int indoormacs;//内机的模拟mac
			bool on;
			int mode;
			string fan;
			int current; //当前温度
			int target; //目标温度
	};


public:
	static kk_handleDeviceInfo* GetInstance();

	//小K组设备，自动补充设备对应的prodID。
	EH::Json::Value XiaoK_Zu_Wang(string kkDevProductId);
	//更改设备状态信息
	void handleDeviceStatusChanged(map<string,kk_handleDeviceInfo::HwSubDev*>&hwSubDevs,map<string,string>&nodeId2channelMap,
			string nodeId,string opcode,EH::Json::Value arg,string pushTopic,string gw_id);
	// //空调内机更改设备状态信息
	// void handleCentralACStatusPush(map<string,kk_handleDeviceInfo::HwSubDev*>&hwSubDevs,map<string,string>&indoorunitsId2AddrMap,string pushTopic,
	// 		string nodeId,EH::Json::Value arg,string opcode);
	//允许加入的设备类型
	bool isValidJoinDeviceType(string kkDevOperateId,string kkDevProductId,string mac);
	//获取全部设备信息
	int onGetDevService(map<string,kk_handleDeviceInfo::HwSubDev*>&hwSubDevs,map<string,vector<string> >& controllerModel,string pushTopic);
	//控制设备
	int onSetDevService(map<string,kk_handleDeviceInfo::HwSubDev*>&hwSubDevs,string sn,EH::Json::Value cmd);
	//下发解析好的命令
	//供：onSetDevService（）调用
	int on_Send_Service(string opcode,string nodeid,string arg,string dev_model_id);
	//建立通道设备模型
	kk_handleDeviceInfo::KKChannelDev* buildChannelDevice(string operateId,string nodeId,string channel,EH::Json::Value status,string devroomid,string devname);

	//添加到房间里
	void addCCuDevicesToRoom(map<string,kk_handleDeviceInfo::HwSubDev*>::iterator&it,map<string,string> NodeId2gwId);

	EH::Json::Value centralACStatusToSet(string fanSpeed,bool on,int runModel,int settingTemperature);

private:
	kk_handleDeviceInfo();

private:
	static kk_handleDeviceInfo* ms_pInstance;

};

#endif
