package iot.lidee.common.core.redis;

import iot.lidee.common.constant.CacheConstants;
import iot.lidee.common.constant.LideeConstant;

/**
 * 缓存key生成器
 *
 * @author bill
 */
public class RedisKeyBuilder {

    /**设备在线列表缓存key*/
    public static String buildDeviceOnlineListKey(){
       return LideeConstant.REDIS.DEVICE_ONLINE_LIST;
    }

    /**设备实时数据key*/
    public static String buildDeviceRtCacheKey(String serialNumber){
        return LideeConstant.REDIS.DEVICE_RUNTIME_DATA + serialNumber;
    }

    /**
     * 设备通讯协议参数
     */
    public static String buildDeviceRtParamsKey(String serialNumber){
        return LideeConstant.REDIS.DEVICE_PROTOCOL_PARAM + serialNumber;
    }

    /**固件版本缓存key*/
    public static String buildFirmwareCachedKey(Long firmwareId){
       return LideeConstant.REDIS.FIRMWARE_VERSION + firmwareId;
    }

    /**属性读取回调缓存key*/
    public static String buildPropReadCacheKey(String serialNumber){
        return LideeConstant.REDIS.PROP_READ_STORE + serialNumber;
    }

    /**
     * 物模型值命名缓存key
     * Key：TSLV:{productId}_{deviceNumber}   HKey:{identity#V/identity#S/identity#M/identity#N}
     */
    public static String buildTSLVCacheKey(Long productId,String serialNumber){
        return LideeConstant.REDIS.DEVICE_PRE_KEY + productId + "_" + serialNumber.toUpperCase();
    }

    /**
     * 物模型缓存key
     * 物模型命名空间：Key:TSL:{productId}  hkey: identity  value: thingsModel
     */
    public static String buildTSLCacheKey(Long productId){
        return LideeConstant.REDIS.TSL_PRE_KEY + productId;
    }

    public static String buildModbusKey(Long productId){
        return LideeConstant.REDIS.MODBUS_PRE_KEY + productId;
    }

    /**录像缓存key*/
    public static String buildSipRecordinfoCacheKey(String recordKey){
        return LideeConstant.REDIS.RECORDINFO_KEY + recordKey;
    }

    /**设备id缓存key*/
    public static String buildSipDeviceidCacheKey(String id){
        return LideeConstant.REDIS.DEVICEID_KEY + id;
    }
    /**ipCSEQ缓存key*/
    public static String buildStreamCacheKey(String steamId){
        return LideeConstant.REDIS.STREAM_KEY + steamId;
    }

    public static String buildStreamCacheKey(String deviceId, String channelId, String stream, String ssrc){
        return LideeConstant.REDIS.STREAM_KEY + deviceId + ":" + channelId + ":" + stream + ":" + ssrc;
    }

    public static String buildInviteCacheKey(String type, String deviceId, String channelId, String stream, String ssrc){
        return LideeConstant.REDIS.INVITE_KEY + type + ":"+ deviceId + ":" + channelId + ":" + stream + ":" + ssrc;
    }

    /**ipCSEQ缓存key*/
    public static String buildSipCSEQCacheKey(String CSEQ){
        return LideeConstant.REDIS.SIP_CSEQ_PREFIX + CSEQ;
    }

    /**rule静默时间缓存key*/
    public static String buildSilentTimeacheKey(String key){
        return LideeConstant.REDIS.RULE_SILENT_TIME + key;
    }

    /**modbus指令缓存key*/
    public static String buildModbusPollCacheKey(String serialNumebr){
        return LideeConstant.REDIS.POLL_MODBUS_KEY + serialNumebr;
    }
    /*缓存设备下发指令消息ID*/
    public static String buildDownMessageIdCacheKey(String serialNumber){
        return LideeConstant.REDIS.DEVICE_MESSAGE_ID + serialNumber;
    }

    /**
     * 缓存产品id，设备编号，协议编号
     */
    public static String buildDeviceMsgCacheKey(String serialNumber){
        return LideeConstant.REDIS.DEVICE_MSG + serialNumber;
    }

    /**
     * 缓存产品id，设备编号，协议编号
     */
    public static String buildSceneModelTagCacheKey(Long sceneModelId){
        return LideeConstant.REDIS.SCENE_MODEL_TAG_ID + sceneModelId;
    }

    public static String buildModbusRuntimeCacheKey(String serialNumber){
        return LideeConstant.REDIS.MODBUS_RUNTIME + serialNumber;
    }

    public static String buildModbusLockCacheKey(String serialNumber){
        return LideeConstant.REDIS.MODBUS_LOCK + serialNumber;
    }

    public static String buildModbusTcpCacheKey(String serialNumber){
        return LideeConstant.REDIS.MODBUS_TCP + serialNumber;
    }

    public static String buildModbusTcpRuntimeCacheKey(String serialNumber){
        return LideeConstant.REDIS.MODBUS_TCP_RUNTIME + serialNumber;
    }


    /**设备OTA升级实时数据*/
    public static String buildDeviceOtaKey(String serialNumber){
        return CacheConstants.DEVICE_OTA_DATA + serialNumber;
    }


}
