package com.goafanti.common.enums;

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

import org.apache.commons.lang3.StringUtils;

public enum SocietyTag {
	SHQY(0, "社会企业"), KYDW(1, "科研单位"), 
	GDWX(2, "高等院校"), KYZJ(3, "科研专家"),
	KJDR(4, "科技达人"),
	FWJG(5, "服务机构"), ZFBM(6, "政府部门"), 
	SH(7, "商会"), XH(8, "协会"),
	QTZZ(9, "其他组织"),
	QTGR(10, "其他个人");

	private SocietyTag(Integer code, String desc) {
		this.code = code;
		this.desc = desc;
	}

	private static Map<Integer, SocietyTag> status = new HashMap<Integer, SocietyTag>();

	static {
		for (SocietyTag value : SocietyTag.values()) {
			status.put(value.getCode(), value);
		}
	}

	public static SocietyTag getStatus(Integer code) {
		if (containsType(code)) {
			return status.get(code);
		}
		return SHQY;
	}
	
	public static String getValueByCode(Integer code){
        for(SocietyTag societyTag:SocietyTag.values()){
            if(code.equals(societyTag.getCode())){
                return societyTag.getDesc();
            }
        }
        return  SHQY.getDesc();
    }
	public static Integer getCodeByValue(String  value){
        for(SocietyTag societyTag:SocietyTag.values()){
            if(value.equals(societyTag.getDesc())){
                return societyTag.getCode();
            }
        }
        return  SHQY.getCode();
    }

	public static SocietyTag getStatus(String code) {
		if (StringUtils.isNumeric(code)) {
			return getStatus(Integer.parseInt(code));
		}
		return SHQY;
	}

	public static boolean containsType(Integer code) {
		return status.containsKey(code);
	}

	private Integer	code;
	private String	desc;

	public Integer getCode() {
		return code;
	}

	public String getDesc() {
		return desc;
	}
}
