package com.zt.plat.module.qms.resource.device.enums;

import com.alibaba.fastjson.JSONObject;

import java.util.Objects;

public enum DeviceBizEnum {

    accept("Accept", "验收"),
    repair("Repair", "维修"),
    demote("Demote", "降级"),
    scrap("Scrap", "报废"),
//    disable("Disable", "停用"),
    enable("Enable", "启用"),
    borrow("Borrow", "借用");
//    giveback("Giveback", "归还");

    public static final Integer switchOn = 1;
    public static final Integer switchOff = 0;

    private String code;
    private String describe;


    DeviceBizEnum(String code, String describe){
        this.code = code;
        this.describe = describe;
    }

    public static DeviceBizEnum getByCode(String code) {
        for (DeviceBizEnum c : DeviceBizEnum.values()) {
            if (c.getCode().equals(code)) {
                return c;
            }
        }
        return null;
    }

    public static String getDescribe(String code) {
        for (DeviceBizEnum c : DeviceBizEnum.values()) {
            if (c.getCode().equals(code)) {
                return c.describe;
            }
        }
        return code;
    }

    public static String getCode(String describe) {
        for (DeviceBizEnum c : DeviceBizEnum.values()) {
            if (c.getDescribe().equals(describe)) {
                return c.code;
            }
        }
        return describe;
    }

    /*
    * 根据业务类型、开关状态，获取状态值
    *
    * */
    public static JSONObject getStateBySwitch(String code, Integer switchState){
        DeviceBizEnum biz = getByCode(code);
        String flag = "";
        boolean updateStateShow = false;
        if(biz == null)
            return null;
        switch (biz){
            case accept:
                flag = String.valueOf(switchState);
                updateStateShow = false;
                break;
            case repair:
                flag = String.valueOf(switchState);
                updateStateShow = true;
                break;
            case demote:
                flag = String.valueOf(switchState);
                updateStateShow = true;
                break;
            case scrap:
                flag = String.valueOf(switchState);
                updateStateShow = true;
                break;
//            case disable:
//                flag = String.valueOf(switchState);
//                updateStateShow = true;
//                break;
            case enable:
                if(Objects.equals(switchState, switchOn))
                    flag = "0";
                else
                    flag = "1";
                updateStateShow = true;
                break;
            case borrow:
                flag = String.valueOf(switchState);
                updateStateShow = true;
                break;
//            case giveback:
//                if(Objects.equals(switchState, DeviceBizEnum.switchOn))
//                    flag = "0";
//                else
//                    flag = "1";
//                updateStateShow = true;
//                break;
            default:
                return null;
        }
        JSONObject json = new JSONObject();
        json.put("flag", flag);
        json.put("updateStateShow", updateStateShow);
        return json;
    }


    public String getCode() {
        return code;
    }

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

    public String getDescribe() {
        return describe;
    }

    public void setDescribe(String describe) {
        this.describe = describe;
    }
    
}
