package cn.freemud.enums;

import com.google.common.collect.Lists;

import java.util.List;

/**
 * All rights Reserved, Designed By www.freemud.cn
 *
 * @version V1.5.1
 * @Title: DeliveryStatus
 * @Package cn.freemud.enums
 * @Description: 简单描述下这个类是做什么用的
 * @author: hang.chai
 * @date: 2018/12/12 14:57
 * @Copyright: 2018 www.freemud.cn Inc. All rights reserved.
 * 注意：本内容仅限于上海非码科技内部传阅，禁止外泄以及用于其他的商业目
 */
public enum DeliveryStatus {

    WATINGORDER(0,"待接单"),
    SYSTEMGETORDER(1,"系统接单"),
    ALLOTRIDER(2,"分配骑手"),
    RIDERARRIVESTORE(3,"骑手到店"),
    RIDERGETMEAL(4,"骑手取餐"),
    RIDERSTARTDELIVERY(5,"开始配送"),
    DELIVERYARRIVED(6,"运单送达"),
    DELIVERYERROR(7,"运单异常"),
    DELIVERYCANCEL(8,"运单取消"),
    DELIVERY_CREATE_SUCCESS(9, "创建配送单成功"),
    ;

    private int code;

    private String desc;

    DeliveryStatus(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public int getCode() {
        return code;
    }

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

    public String getDesc() {
        return desc;
    }

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

    public static DeliveryStatus getDeliveryStatusByCode(int code) {
        for (DeliveryStatus obj : values()) {
            if (obj.code == code) {
                return obj;
            }
        }
        return null;
    }

    /**
     * @Description: 校验配送单状态是否需要推送给开放平台
     * @param status
     * @return
     */
    public static boolean checkDeliveryStatueForPlatform(int status) {
        DeliveryStatus deliveryStatus = DeliveryStatus.getDeliveryStatusByCode(status);
        if (null == deliveryStatus) return false;

        List<DeliveryStatus> targetList = Lists.newArrayList(DeliveryStatus.ALLOTRIDER,
                DeliveryStatus.RIDERGETMEAL,
                DeliveryStatus.RIDERSTARTDELIVERY,
                DeliveryStatus.DELIVERYARRIVED,
                DeliveryStatus.DELIVERYERROR,
                DeliveryStatus.DELIVERYCANCEL
        );
        if (targetList.contains(deliveryStatus)) {
            return true;
        }
        return false;
    }

}
