#pragma once
#include <map>
#include <string>
#include <vector>

enum class EAlertType
{
	SYS = 1,	// 系统告警
	USER = 2,	// 用户告警
	DEVICE = 3,	// 设备告警
};

enum class EDeviceType
{
	NUL = 0,
	//1	变压器	0
	//2	配电柜	0
	E_METER = 3,	//3	电表	1
	E_METER_TD = 4, //4	电表（台区）
	//5	空调	0
	//6	照明	0
	//7	消防	0
	//8	光照监测设备	0
	//9	风速监测设备	0
	//10	温湿度监测设备	0
	//11	烟感监测设备	0
	//12	水浸传感器	0
	//13	视频监控	4
	//14	冷机	0
	GATEWAY = 15, // 网关	0
	//100	储能预制舱	1
	EMS = 101,//101	EMS	1
	PCS = 102, //102	PCS	1
	PCU = 103, //103	PCU	1
	BMS = 104, //104	BMS	1
	BCU = 105,	//105	BCU	1
	CHARGER = 106, //106	充电桩	2
	//107	充电枪	2
	//108	集中器	2
	//109	光伏板	3
	//110	风力发电机	3
};


struct RegAddrUnit
{
	std::string key;
	std::string datatype;
	std::string name;
	std::string remark;
	int ratio {1};
	int alert {0};

	RegAddrUnit() {}
	RegAddrUnit(std::string key, std::string datatype, int alert, std::string name, std::string remark)
		: key(key), datatype(datatype), alert(alert), name(name), remark(remark)
	{
	}
};


// 需要在前端展示的设备参数
struct DeviceParamAddr
{
	std::string name;
	std::string addr;
	std::string defaultVal;
	std::string unit;
	float ratio {1.0};
	DeviceParamAddr() {};
	DeviceParamAddr(std::string name, std::string addr, std::string defaultVal, std::string unit, float ratio = 1.0f)
		: name(name), addr(addr), defaultVal(defaultVal), unit(unit), ratio(ratio)
	{
		if (this->ratio == 0.0)
		{
			this->ratio = 1.0f;
		}
	};
};

class REGAddr
{
public:
	// key: 寄存器地址
	static std::map<std::string, std::map<std::string, RegAddrUnit>> s_mapReg;

	static std::map<int, std::vector<DeviceParamAddr>> s_mapDeviceAddrParam;
	static std::map<int, std::vector<std::string>> s_mapDeviceAddrCurve;
	static std::map<int, std::map<std::string, std::map<std::string, std::string>>> g_mapRegAddrValStr;
	static std::map<int, std::map<std::string, RegAddrUnit>> g_mapRegDeviceType;

	static void load(std::string filename);
	static void loadParamAddr(std::string filename);

	static std::map<std::string, RegAddrUnit>* getRegMap(std::string name);

	static std::map<std::string, RegAddrUnit>* getRegMapByDeviceType(int deviceType);

	static std::vector<DeviceParamAddr>& GetDeviceParamAddrs(int deviceType);
};