package com.hw.common.core.constant;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: TdEngine服务常量
 * @ClassName: TdEngineConstants
 * @Author  : xins
 * @Date    :2023-09-05  9:47
 * @Version :1.0
 */
public class TdEngineConstants {

    public static final String DEFAULT_FIRST_FIELD_NAME = "ts";//timestamp格式首字段，必须

    public static final String DEFAULT_ORDER_BY_MODE = "desc";//默认排序方式，逆序

    public static final String PAYLOAD_TS = "timestamp";//协议上传ts的key

    public static final String PAYLOAD_PARAM = "param";//协议上传的param key

    public static final String PAYLOAD_DATATYPE = "datatype";//协议上传数据数据类型的key
    public static final String PAYLOAD_DATAVALUE = "datavalue";//协议上传数据的key

    public static final String PAYLOAD_DEVICE_CODE = "uid";//协议上传设备编号的key

    public static final String PAYLOAD_DEVICE_DATA_TYPE_IMAGE = "image";//协议上传图片的key

    public static final String PAYLOAD_DEVICE_DATA_TYPE_TYPE = "type";//协议上传图片类型的key
    public static final String PAYLOAD_DEVICE_DATA_TYPE_TYPE_FIRSET_UPPER = "Type";//协议上传图片类型的key

//    public static final String DEFAULT_DB_NAME_PREFIX = "db_scene_";//数据库名称前缀

    public static final String DEFAULT_SUPER_TABLE_NAME_PREFIX = "st_devicemode_";//超级表名称前缀
    public static final String DEFAULT_TABLE_NAME_PREFIX = "t_device_";//数据表名称前缀

    public static final String DEFAULT_DEVICE_STATUS_SUPER_TABLE_NAME= "st_ds";//设备状态超级表名称
    public static final String DEFAULT_DEVICE_STATUS_TABLE_NAME_PREFIX = "t_ds_";//设备状态数据表名称前缀

    public static final String PLATFORM_DB_NAME = "db_hwsaas";//全局数据库名称

    public static final String ST_TAG_DEVICECODE = "devicecode";
    public static final int ST_TAG_DEVICECODE_TYPE = 10;
    public static final int ST_TAG_DEVICECODE_SIZE=50;

    public static final String ST_TAG_DEVICENAME = "devicename";

    public static final String ST_TAG_DEVICETYPE = "devicetype";
    public static final String ST_TAG_ONLINESTATUS = "onlinestatus";
    public static final int ST_TAG_DEVICENAME_TYPE = 10;
    public static final int ST_TAG_DEVICENAME_SIZE=200;

    public static final String ST_TAG_DEVICEID = "deviceid";
    public static final int ST_TAG_DEVICEID_TYPE = 2;

    public static final String ST_TAG_DEVICEMODEID = "devicemodeid";
    public static final int ST_TAG_DEVICEMODEID_TYPE = 2;

    public static final String ST_TAG_MONITORUNITID = "monitorunitid";

    public static final String ST_TAG_SCENEID = "sceneid";

    public static final int ST_TAG_MONITORUNITID_TYPE = 2;


    /*能源部分*/
    public static final String EMS_DATABASE_NAME  = "db_hwmes";
    public static final String EMS_TABLE_NAME_PREFIX = "t_e_";

    public static final String ST_TAG_EMS_MONITOROBJID = "monitorobjid";//计量设备编号
    public static final String ST_TAG_EMS_MONITORID = "monitorid";//计量设备主键
    public static final String ST_TAG_EMS_MONITORNAME = "monitorname";//计量设备名称
    public static final String ST_TAG_EMS_BUILDID = "buildid";//建筑类型ID（多个以,隔开）

    /**
     * 需要转换的key
     */
    public static final Map<String, String> TDENGINE_KEY_TRANSFER_MAP = new HashMap<String, String>();

    static {
        TDENGINE_KEY_TRANSFER_MAP.put("value", "value1");
    }

    /**
     * 禁止的功能标识符
     */
    public static final List<String> ABNDON_FUNCTION_IDENTIFIERS = Arrays.asList("ts","value1","type");

    public static final Map<String, String> DEVICE_DATA_COLUMN_MAP = new HashMap<String, String>();

    static {
        DEVICE_DATA_COLUMN_MAP.put(ST_TAG_DEVICECODE, "设备编号");
        DEVICE_DATA_COLUMN_MAP.put(ST_TAG_DEVICENAME, "设备名称");
        DEVICE_DATA_COLUMN_MAP.put(DEFAULT_FIRST_FIELD_NAME, "时间");
    }

    /**
     * @return String
     * @param: sceneId
     * @description 获取数据库名称
     * @author xins
     * @date 2023-09-05 9:42
     */
    public static String getDatabaseName() {
        return PLATFORM_DB_NAME;
    }

    /**
     * @param: deviceModeId
     * @description 获取超级表名称
     * @author xins
     * @date 2023-09-16 14:42
     * @return String
     */
    public static String getSuperTableName(Long deviceModeId) {
        return DEFAULT_SUPER_TABLE_NAME_PREFIX + deviceModeId;
    }

    /**
     * @param: deviceId
     * @return String
     * @description 获取设备数据子表名称
     * @author xins
     * @date 2023-09-05 9:42
     */
    public static String getDeviceDataTableName(Long deviceId) {
        return DEFAULT_TABLE_NAME_PREFIX + deviceId;
    }

    /**
     * @param: deviceId
     * @return String
     * @description 获取设备状态信息数据子表名称
     * @author xins
     * @date 2023-09-05 9:42
     */
    public static String getDeviceStatusTableName(Long deviceId) {
        return DEFAULT_DEVICE_STATUS_TABLE_NAME_PREFIX + deviceId;
    }

    /**
     * 获取能源子表的表名称
     * @param monitorId 计量设备编号
     * @return String
     */
    public static String getEmsTableName(String monitorId){
         return EMS_TABLE_NAME_PREFIX + monitorId;
    }

}
