package com.goafanti.common.enums;

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

import org.apache.commons.lang3.StringUtils;

public enum VoucherSourceType {
	
	YQGR(0, "邀请个人"),
	YQFWS(1, "邀请服务商"),
	BYQGR(2, "被邀请个人"),
	BYQFWS(3, "被邀请服务商"),
	HD(3, "活动"),
	OTHER(3, "其他");

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

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

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

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

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

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

}
