package cn.estsh.i3plus.pojo.base.enumutil;

import com.fasterxml.jackson.annotation.JsonFormat;

/**
 * @Description :
 * @Reference :
 * @Author : yunhao
 * @CreateDate : 2019-10-29 13:37
 * @Modify:
 **/
public class LacEnumUtil {

    /**
     * 适配器类型
     */
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public enum SUIT_CASE_TYPE {
        SOFTWARE(10, "软件"),
        HARDWARE(20,  "硬件");

        private int value;
        private String description;

        private SUIT_CASE_TYPE (int value, String description) {
            this.value = value;
            this.description = description;
        }

        public int getValue() {
            return value;
        }

        public String getDescription() {
            return description;
        }

        public static String valueOfDescription(int val) {
            String tmp = null;
            for (int i = 0; i < values().length; i++) {
                if (values()[i].value == val) {
                    tmp = values()[i].description;
                }
            }
            return tmp;
        }

        public static LacEnumUtil.SUIT_CASE_TYPE valueOf(int val) {
            String tmp = null;
            for (int i = 0; i < values().length; i++) {
                if (values()[i].value == val) {
                    return values()[i];
                }
            }
            return null;
        }
    }

    /**
     * 硬件类型
     */
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public enum HARDWARE_TYPE {
        OPC_READ(10, "读OPC"),
        OPC_WRITE(20,  "写OPC"),
        OPC_SUBSCRIPTION(30,  "订阅OPC");

        private int value;
        private String description;

        private HARDWARE_TYPE (int value, String description) {
            this.value = value;
            this.description = description;
        }

        public int getValue() {
            return value;
        }

        public String getDescription() {
            return description;
        }

        public static String valueOfDescription(int val) {
            String tmp = null;
            for (int i = 0; i < values().length; i++) {
                if (values()[i].value == val) {
                    tmp = values()[i].description;
                }
            }
            return tmp;
        }

        public static LacEnumUtil.HARDWARE_TYPE valueOf(int val) {
            String tmp = null;
            for (int i = 0; i < values().length; i++) {
                if (values()[i].value == val) {
                    return values()[i];
                }
            }
            return null;
        }
    }

    /**
     * 参数类型
     */
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public enum PARAM_TYPE{
        OUT_PARAM(1,"出参"),
        IN_PARAM(2,"入参");

        private int value;
        private String description;

        PARAM_TYPE(int value, String description) {
            this.value = value;
            this.description = description;
        }

        public int getValue() {
            return value;
        }

        public String getDescription() {
            return description;
        }

        public static String valueOfDescription(int val) {
            String tmp = null;
            for (int i = 0; i < values().length; i++) {
                if (values()[i].value == val) {
                    tmp = values()[i].description;
                }
            }
            return tmp;
        }
    }

    /**
     * 指令集状态
     */
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public enum STACK_STATUS{
        INIT(10,"初始化"),
        WAIT(20,"等待中"),
        RUNNING(30,"运行中"),
        PAUSE(40,"手动暂停"),
        FINISH(100,"执行完成"),
        RUN_ERROR(101,"运行异常"),
        RUN_STOP(102,"手动结束");

        private int value;
        private String description;

        STACK_STATUS(int value, String description) {
            this.value = value;
            this.description = description;
        }

        public int getValue() {
            return value;
        }

        public String getDescription() {
            return description;
        }

        public static String valueOfDescription(int val) {
            String tmp = null;
            for (int i = 0; i < values().length; i++) {
                if (values()[i].value == val) {
                    tmp = values()[i].description;
                }
            }
            return tmp;
        }

        public static boolean isRunning(int val) {
            return RUNNING.getValue() == val;
        }
    }

    /**
     * 返回方式
     */
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public enum RETURN_METHOD{
        SYNC(1,"同步"),
        ASYNC(2,"异步");

        private int value;
        private String description;

        RETURN_METHOD(int value, String description) {
            this.value = value;
            this.description = description;
        }

        public int getValue() {
            return value;
        }

        public String getDescription() {
            return description;
        }

        public static String valueOfDescription(int val) {
            String tmp = null;
            for (int i = 0; i < values().length; i++) {
                if (values()[i].value == val) {
                    tmp = values()[i].description;
                }
            }
            return tmp;
        }
    }

    /**
     * 参数值类型
     */
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public enum PARAM_VALUE_TYPE{
        INTEGER(1,"整数"),
        STRING(2,"字符串"),
        FLOAT(3,"浮点"),
        ORGIN(99,"原始数据");

        private int value;
        private String description;

        PARAM_VALUE_TYPE(int value, String description) {
            this.value = value;
            this.description = description;
        }

        public int getValue() {
            return value;
        }

        public String getDescription() {
            return description;
        }

        public static String valueOfDescription(int val) {
            String tmp = null;
            for (int i = 0; i < values().length; i++) {
                if (values()[i].value == val) {
                    tmp = values()[i].description;
                }
            }
            return tmp;
        }
    }

    /**
     * 指令操作对象类型
     */
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public enum OPERATE_OBJ_TYPE{
        COMMAND_STACK(10,"指令集"),
        COMMAND_STACK_STEP(20,"指令集步骤"),
        COMMAND_STACK_STEP_TASK(30,"指令集步骤任务");

        private int value;
        private String description;

        OPERATE_OBJ_TYPE(int value, String description) {
            this.value = value;
            this.description = description;
        }

        public int getValue() {
            return value;
        }

        public String getDescription() {
            return description;
        }

        public static String valueOfDescription(int val) {
            String tmp = null;
            for (int i = 0; i < values().length; i++) {
                if (values()[i].value == val) {
                    tmp = values()[i].description;
                }
            }
            return tmp;
        }
    }

    /**
     * 操作指令
     */
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public enum OPERATE_COMMAND{
        STACK_RESUME(11,"恢复",OPERATE_OBJ_TYPE.COMMAND_STACK),
        STACK_PAUSE(12,"暂停",OPERATE_OBJ_TYPE.COMMAND_STACK),
        STACK_CLOSE(13,"关闭",OPERATE_OBJ_TYPE.COMMAND_STACK),
        STACK_SKIP(14,"跳过",OPERATE_OBJ_TYPE.COMMAND_STACK),
        TASK_INTERRUPT(21,"中断",OPERATE_OBJ_TYPE.COMMAND_STACK_STEP_TASK);

        private int value;
        private String description;
        private OPERATE_OBJ_TYPE operateObjType;

        OPERATE_COMMAND(int value, String description,OPERATE_OBJ_TYPE operateObjType) {
            this.value = value;
            this.description = description;
            this.operateObjType = operateObjType;
        }

        public int getValue() {
            return value;
        }

        public String getDescription() {
            return description;
        }

        public static String valueOfDescription(int val) {
            String tmp = null;
            for (int i = 0; i < values().length; i++) {
                if (values()[i].value == val) {
                    tmp = values()[i].description;
                }
            }
            return tmp;
        }

        public static OPERATE_COMMAND valueOf(int val) {
            String tmp = null;
            for (int i = 0; i < values().length; i++) {
                if (values()[i].value == val) {
                    return values()[i];
                }
            }
            return null;
        }

        public OPERATE_OBJ_TYPE getOperateObjType() {
            return operateObjType;
        }
    }

    /**
     * 逻辑运算符
     */
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public enum LOGICAL_OPERATOR{
        OR(10,"或","||"),
        AND(20,"与","&&");

        private int value;
        private String description;
        private String operator;

        LOGICAL_OPERATOR(int value, String description, String operator) {
            this.value = value;
            this.description = description;
            this.operator = operator;
        }

        public int getValue() {
            return value;
        }

        public String getDescription() {
            return description;
        }

        public static String valueOfDescription(int val) {
            String tmp = null;
            for (int i = 0; i < values().length; i++) {
                if (values()[i].value == val) {
                    tmp = values()[i].description;
                }
            }
            return tmp;
        }

        public static String valueOfOperator(int val) {
            String tmp = null;
            for (int i = 0; i < values().length; i++) {
                if (values()[i].value == val) {
                    tmp = values()[i].operator;
                }
            }
            return tmp;
        }

    }

    /**
     * 关系运算符
     */
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public enum RELATIONAL_OPERATOR{
        GT(10,"大于",">"),
        LT(20,"小于","<"),
        EQ(30,"等于","=="),
        NE(40,"不等于","!="),
        GE(50,"大于等于",">="),
        LE(60,"小于等于","<=");

        private int value;
        private String description;
        private String operator;

        RELATIONAL_OPERATOR(int value, String description,String operator) {
            this.value = value;
            this.description = description;
            this.operator = operator;
        }

        public int getValue() {
            return value;
        }

        public String getDescription() {
            return description;
        }

        public static String valueOfDescription(int val) {
            String tmp = null;
            for (int i = 0; i < values().length; i++) {
                if (values()[i].value == val) {
                    tmp = values()[i].description;
                }
            }
            return tmp;
        }

        public static RELATIONAL_OPERATOR valueOf(int val) {
            RELATIONAL_OPERATOR tmp = EQ;
            for (int i = 0; i < values().length; i++) {
                if (values()[i].value == val) {
                    tmp = values()[i];
                }
            }
            return tmp;
        }

    }

    /**
     * 任务检查类型
     */
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public enum TASK_CHECK_TYPE{
        MASTER(10,"主"),
        SLAVE(20,"从");

        private int value;
        private String description;

        TASK_CHECK_TYPE(int value, String description) {
            this.value = value;
            this.description = description;
        }

        public int getValue() {
            return value;
        }

        public String getDescription() {
            return description;
        }

        public static String valueOfDescription(int val) {
            String tmp = null;
            for (int i = 0; i < values().length; i++) {
                if (values()[i].value == val) {
                    tmp = values()[i].description;
                }
            }
            return tmp;
        }

    }

}
