/**
 * All rights Reserved, Designed By www.freemud.cn
 *
 * @Title: OrderType
 * @Package cn.freemud.enums
 * @Description: 订单类型
 * @author: liming.guo
 * @date: 2018/5/21 14:43
 * @version V1.0
 * @Copyright: 2018 www.freemud.cn Inc. All rights reserved.
 * 注意：本内容仅限于上海非码科技内部传阅，禁止外泄以及用于其他的商业目
 */
package cn.freemud.enums;

import com.freemud.sdk.api.assortment.order.adapter.OrderSdkAdapter;
import com.google.common.collect.Lists;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 基础服务订单类型如下:
 * 1=常规堂食，
 * 2=预约堂食，
 * 3=常规外送，
 * 4=预约外送，
 * 5=常规自取，
 * 6=预约自取
 *
 * @see OrderSdkAdapter#getOldOrderType(java.lang.Integer)
 * 该类为老订单类型:
 */
public enum OrderType {
    TAKE_OUT(1, "外卖", "takeOut"),
    PRE_ORDER(2, "预订单", "preOrder"),
    MALL(3, "商城", "mall"),
    COLLECT_GOODS(4, "打包带走", "collectGoods"),
    EAT_IN(5, "店内就餐", "eatIn");

    private Integer code;
    private String desc;
    /**
     * 对应取餐码key规则
     */
    private String tackDesc;

    OrderType(Integer code, String desc, String tackDesc) {
        this.code = code;
        this.desc = desc;
        this.tackDesc = tackDesc;
    }

    public static List<Integer> getAllCodes() {
        List<Integer> list = Lists.newArrayList();
        for (OrderType orderType : values()) {
            list.add(orderType.getCode());
        }
        return list;
    }


    public static OrderType getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (OrderType orderType : values()) {
            if (orderType.getCode().equals(code)) {
                return orderType;
            }
        }
        return null;
    }

    public static List getByCode(List<Integer> list) {
        List returnList = new ArrayList();
        if (CollectionUtils.isEmpty(list)) {
            return returnList;
        }
        for (OrderType orderType : values()) {
            for (Integer code : list) {
                if (orderType.getCode().equals(code)) {
                    returnList.add(code);
                }
            }
        }
        return returnList;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public String getTackDesc() {
        return tackDesc;
    }

    public void setTackDesc(String tackDesc) {
        this.tackDesc = tackDesc;
    }
}
