package net.wicp.tams.app.duckula.controller.bean.constant;

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

import org.apache.commons.lang3.StringUtils;

import net.wicp.tams.common.constant.dic.intf.IEnumCombobox;

public enum DorisRole implements IEnumCombobox {

	follower("FE-Follower", "FE", true),

	master("FE-Master", "FE", true),

	observer("FE-Observer", "FE", false),

	be("BE", "BE", true);

	private final String desc;
	private final String type;// BE/FE

	private final boolean need;// 是否一个集群内必须

	private DorisRole(String desc, String type, boolean need) {
		this.desc = desc;
		this.type = type;
		this.need = need;
	}

	@Override
	public String getDesc() {
		return this.desc;
	}

	@Override
	public String getDesc_en() {
		return this.desc;
	}

	@Override
	public String getDesc_zh() {
		return this.desc;
	}

	@Override
	public String getName() {
		return this.name();
	}

	public String getType() {
		return type;
	}

	public boolean isNeed() {
		return need;
	}

	// 一定需要存在的角色状态
	public static Map<DorisRole, Boolean> isExit() {
		Map<DorisRole, Boolean> retmap = new HashMap<DorisRole, Boolean>();
		DorisRole[] values = DorisRole.values();
		for (DorisRole dorisRole : values) {
			if (dorisRole.isNeed()) {
				retmap.put(dorisRole, Boolean.FALSE);
			}
		}
		return retmap;
	}

	public static DorisRole find(String name) {
		if (StringUtils.isEmpty(name)) {
			return null;
		}
		for (DorisRole ele : DorisRole.values()) {
			if (name.equalsIgnoreCase(ele.name())) {
				return ele;
			}
		}
		return null;
	}

}
