package com.yeejoin.amos.boot.module.statistics.api.enums;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

@AllArgsConstructor
@Getter
public enum DataQualityScoreEnum {

    /**
     * *设备等级
     */

    I("一级", "3"),
    II("二级", "2"),
    III("三级", "1"),
    ;

    private String name;
    private String code;

    public static Map<String, String> getName = new HashMap<>();
    public static Map<String, String> getCode = new HashMap<>();


    static {
        for (DataQualityScoreEnum e : DataQualityScoreEnum.values()) {
            getName.put(e.code, e.name);
            getCode.put(e.name, e.code);
        }
    }

    public static JSONArray getAll(){
        JSONArray jsonArray = new JSONArray();
        for (DataQualityScoreEnum e : DataQualityScoreEnum.values()) {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("label",e.name);
            jsonObject.put("value",e.name);
            jsonObject.put("key",e.code);
            jsonArray.add(jsonObject);
        }
        return jsonArray;
    }

    public static String getNameByCode(String code) {
        for (DataQualityScoreEnum e : EnumSet.allOf(DataQualityScoreEnum.class)) {
            if(e.getCode().equals(code)){
                return e.getName();
            }
        }
        return null;
    }
}
