package com.goafanti.common.enums;

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

import org.apache.commons.lang3.StringUtils;

public enum OfficialType {
	SYXX(0,"实用新型"),
	FMZL(1,"发明专利"),
	WGZL(2,"外观专利"),
	NOT(99,"未知");
	
	private OfficialType(Integer code, String desc) {
		this.code = code;
		this.desc = desc;
	}

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

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

	public static String getValueByCode(Integer code){
        for(OfficialType o:OfficialType.values()){
            if(code.equals(o.getCode())){
                return o.getDesc();
            }
        }
        return  NOT.getDesc();
    }
	public static OfficialType getStatus(Integer code) {
		if (containsType(code)) {
			return status.get(code);
		}
		return NOT;
	}

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

	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;
	} 

}
