package org.nl.acs.device.device_driver;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

/**
 * 驱动类型
 * https://blog.csdn.net/moneyshi/article/details/82978073
 */
public enum DriverTypeEnum {

    // 设备驱动
    ORDINARY_SITE(1, "standard_ordinary_site", "普通站点", "conveyor"),

    INSPECT_SITE(2, "standard_inspect_site", "检测站点", "conveyor"),

    STORAGE(3, "standard_storage", "标准版-货架", "storage"),

    SCANNER(4, "standard_scanner", "标准版-扫码器", "scanner"),

    INSPECT_CONVEYOR_CONTROL(5, "standard_conveyor_control", "标准版-输送机-控制点", "conveyor"),

    INSPECT_CONVEYOR_MONITOR(6, "standard_conveyor_monitor", "标准版-输送机-监控点", "conveyor"),

    AGV_NDC_ONE(7, "agv_ndc_one", "NDCAGV", "agv"),

    AGV_NDC_TWO(8, "agv_ndc_two", "NDC2楼AGV", "agv"),

    XGAGV(9, "xg_agv", "xg_agv", "agv"),

    AUTODOOR(10, "standard_autodoor", "标准版-自动门", "autodoor"),
    TUBANXIAN_SITE(11, "tubanxian_site", "涂板线", "conveyor"),
    GUHUASHI_SITE(12, "guhuashi_site", "固化室", "conveyor"),
    TIANNENG_SITE(13, "tianneng_site", "天能-检测站点", "conveyor"),

    BAOSHIJIAN_SITE(14, "baoshijian_site", "保湿间", "conveyor"),


    SSX(15, "ssx", "输送线", "conveyor"),
    HJ1(16, "hj1", "桁架1", "conveyor"),
    HJ2(17, "hj2", "桁架2", "conveyor");


    //驱动索引
    private int index;
    //驱动编码
    private String code;
    // 驱动名字
    private String name;
    //驱动描述
    private String desc;
    //设备驱动类型
    private String type;

    // 构造方法
    DriverTypeEnum(int index, String code, String name, String type) {
        this.index = index;
        this.code = code;
        this.name = name;
        this.type = type;
    }


    public static JSONArray getList() {
        JSONArray arr = new JSONArray();
        for (DriverTypeEnum em : DriverTypeEnum.values()) {
            JSONObject json = new JSONObject();
            json.put("code", em.getCode());
            json.put("name", em.getName());
            arr.add(json);
        }
        return arr;
    }

    public static JSONArray getListByType(String type) {
        JSONArray arr = new JSONArray();
        for (DriverTypeEnum em : DriverTypeEnum.values()) {
            if (em.getType().equals(type)) {
                JSONObject json = new JSONObject();
                json.put("code", em.getCode());
                json.put("name", em.getName());
                arr.add(json);
            }
        }
        return arr;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public static String getName(String code) {
        for (DriverTypeEnum c : DriverTypeEnum.values()) {
            if (c.code == code) {
                return c.name;
            }
        }
        return null;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }
}
