package cn.superdesk.uniorder.common.enums.thirdpart.jd;

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

/**
 * @Description: 京东 订单类型 原始订单 子订单
 * @Author: linjinyu
 * @CreateDate: 2021/10/21 上午10:44
 * @UpdateUser: linjinyu
 * @UpdateDate: 2021/10/21 上午10:44
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
public enum JdOrderTypeEnum {

	UNKNOW(-1, "UNKNOW"),
	原始订单(1, "原始订单"),
	子订单(2, "子订单"),
	;

	private Integer key;
	private String  desc;

	JdOrderTypeEnum(Integer key, String desc) {
		this.key = key;
		this.desc = desc;
	}

	public Integer getKey() {
		return key;
	}

	public String getDesc() {
		return desc;
	}

	public static String getDesc(Integer key) {
		for (JdOrderTypeEnum c : JdOrderTypeEnum.values()) {
			if (c.key.equals(key)) {
				return c.getDesc();
			}
		}
		return null;
	}

	private static final Map<Integer, JdOrderTypeEnum> LOOKUP = new HashMap<>();

	static {
		for (JdOrderTypeEnum s : EnumSet.allOf(JdOrderTypeEnum.class)) {
			LOOKUP.put(s.getKey(), s);
		}
	}

	public static JdOrderTypeEnum get(Integer key) {
		return LOOKUP.get(key);
	}

	public static JdOrderTypeEnum getByDesc(String desc) {
		for (JdOrderTypeEnum stateEnum : JdOrderTypeEnum.values()) {
			if (stateEnum.desc.equals(desc)) {
				return stateEnum;
			}
		}
		return JdOrderTypeEnum.UNKNOW;
	}
}
