package com.imdroid.secapi.dto;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * GNSS收发统计消息，每个工作周期结束的时候统计一次
 *
 * @author LiGang
 */
@Data
@TableName(value = "warningcfg")
public class WarningCfg {
    // device type definition
    public static final short TYPE_GNSS = 1;
    public static final short TYPE_SOLAR_DTU = 2;
    public static final short TYPE_IMETER = 3;

    // warning code definition
    public static final int TYPE_LOW_VOLTAGE = 0x01;
    public static final String TYPE_NAME_LOW_VOLTAGE = "电压低";
    public static final int TYPE_LOW_RSSI = 0x02;
    public static final String TYPE_NAME_LOW_RSSI = "信号弱";
    public static final int TYPE_DEVICE_OFF_LINE = 0x04;
    public static final String TYPE_NAME_DEVICE_OFF_LINE = "设备离线";
    public static final int TYPE_RX_MUCH_UNKNOWN = 0x10;
    public static final String TYPE_NAME_RX_MUCH_UNKNOWN = "未知报文过多";
    public static final int TYPE_LESS_INUSE_SAT = 0x20;
    public static final String TYPE_NAME_LESS_INUSE_SAT = "可用卫星少";
    public static final int TYPE_LESS_D3XX = 0x40;
    public static final String TYPE_NAME_LESS_D3XX = "RTCM少";
    public static final int TYPE_LESS_B562 = 0x80;
    public static final String TYPE_NAME_LESS_B562 = "固定解少";
    public static final int TYPE_NO_FIXED_RESULT = 0x100;
    public static final String TYPE_NAME_NO_FIXED_RESULT = "连续无固定解";
    //public static final int TYPE_BS_NO_RESULT = 0x200;
    //public static final String TYPE_NAME_BS_NO_RESULT = "基站下的测站均无解";
    public static final int TYPE_INCLINE = 0x400;
    public static final String TYPE_NAME_INCLINE = "异常倾斜";

    // warning level definition
    public static final short LEVEL_0 = 0; //正常
    public static final short LEVEL_1 = 1; //一般
    public static final short LEVEL_2 = 2; //严重

    @TableId(value = "id", type = IdType.AUTO)
    Long id;
    Short devicetype;
    Integer type;
    String typename;
    Integer value;
    Short level;

    public static List<String> parseCode(int code){
        List<String> warningInfo = new ArrayList<>();
        if((code & TYPE_LOW_VOLTAGE) !=0) warningInfo.add(TYPE_NAME_LOW_VOLTAGE);
        if((code & TYPE_LOW_RSSI) !=0) warningInfo.add(TYPE_NAME_LOW_RSSI);
        if((code & TYPE_DEVICE_OFF_LINE) !=0) warningInfo.add(TYPE_NAME_DEVICE_OFF_LINE);
        if((code & TYPE_RX_MUCH_UNKNOWN) !=0) warningInfo.add(TYPE_NAME_RX_MUCH_UNKNOWN);
        if((code & TYPE_LESS_INUSE_SAT) !=0) warningInfo.add(TYPE_NAME_LESS_INUSE_SAT);
        if((code & TYPE_LESS_D3XX) !=0) warningInfo.add(TYPE_NAME_LESS_D3XX);
        if((code & TYPE_LESS_B562) !=0) warningInfo.add(TYPE_NAME_LESS_B562);
        if((code & TYPE_NO_FIXED_RESULT) !=0) warningInfo.add(TYPE_NAME_NO_FIXED_RESULT);
        //if((code & TYPE_BS_NO_RESULT) !=0) warningInfo.add(TYPE_NAME_BS_NO_RESULT);
        if((code & TYPE_INCLINE) !=0) warningInfo.add(TYPE_NAME_INCLINE);
        return warningInfo;
    }
}
