package com.goafanti.common.enums;

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

import org.apache.commons.lang3.StringUtils;

public enum UserType {
	PERSONAL(0, "个人账号"), ORGANIZATION(1, "组织账号");

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

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

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

	public static boolean isPersonal(Integer code) {
		return PERSONAL == getStatus(code);
	}

	public static UserType getStatus(Integer code) {
		if (containsType(code)) {
			return status.get(code);
		}
		return PERSONAL;
	}

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

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