
package com.tmerclub.cloud.api.order.constant;

import java.util.Objects;

/**
 * 订单状态
 * @author tmerclub
 * @date 2020/12/18
 */
public enum OrderStatus {

    /**
     * 没有付款.待付款
     */
    UNPAY(1, "待付款", "待付款"),

    /**
     * 已经付款,但卖家没有发货.待发货
     */
    PAYED(2, "待发货", "待自提"),

    /**
     * 发货，导致实际库存减少，没有确认收货.待收货
     */
    CONSIGNMENT(3, "待收货", "已自提"),

    /**
     * 订单确认收货成功，购买数增加1.
     */
    SUCCESS(5, "已收货", "已收货"),

    /**
     * 交易失败,还原库存
     */
    CLOSE(6, "交易失败", "交易失败"),

    /**
     * 待成团
     */
    WAIT_GROUP(7, "待成团", "待成团"),

    /**
     * 待采购
     */
    WAIT_PURCHASE(8, "待采购", "待采购"),

    /**
     * 待付尾款
     */
    WAIT_BALANCE(9, "待付尾款", "待付尾款"),

    /**
     * cue订单状态
     */
    CUE_PENDING_AUDIT(10, "待审核",""),
    CUE_AUDIT_PASS(11, "审核通过(待发货)",""),
    CUE_AUDIT_FAIL(12, "审核拒绝",""),
    CUE_FINISH_DELIVERY(13, "已发货",""),
    CUE_FINISH_RECEIPT(14, "已收货(评估中)",""),
    CUE_EVALUATION_SUCCESS(15, "评估成功(给出价格)",""),
    CUE_EVALUATION_FAIL(16, "评估失败(退回)",""),
    CUE_EVALUATION_FAIL_FILLED_RETURN_ADDRESS(17, "评估失败用户已填写回邮地址",""),
    CUE_EVALUATION_FAIL_COMPLETED(18, "评估失败(已退回)",""),
    CUE_EVALUATION_SUCCESS_PAY(5, "价格满意(结束)",""),
    CUE_EVALUATION_SUCCESS_PRICE_DISCONTENT(19, "价格不满意(已填写回邮地址)",""),
    CUE_EVALUATION_SUCCESS_COMPLETED(20, "价格不满意(已完成)","");

    private final Integer num;
    private final String deliveryName;
    private final String stationName;

    public Integer value() {
        return num;
    }

    public String deliveryName() {
        return deliveryName;
    }

    public String stationName() {
        return stationName;
    }

    OrderStatus(Integer num, String deliveryName, String stationName) {
        this.num = num;
        this.deliveryName = deliveryName;
        this.stationName = stationName;
    }

    public static OrderStatus instance(Integer value) {
        OrderStatus[] enums = values();
        for (OrderStatus statusEnum : enums) {
            if (statusEnum.value().equals(value)) {
                return statusEnum;
            }
        }
        return null;
    }

    public static String getDeliveryName(Integer value) {
        OrderStatus[] enums = values();
        for (OrderStatus statusEnum : enums) {
            if (statusEnum.value().equals(value)) {
                return statusEnum.deliveryName;
            }
        }
        return null;
    }

    public static String getStationName(Integer value) {
        OrderStatus[] enums = values();
        for (OrderStatus statusEnum : enums) {
            if (!statusEnum.value().equals(value)) {
                return statusEnum.stationName;
            }
        }
        return null;
    }

    public static boolean unPay(Integer status) {
        if (status == null) {
            return false;
        }
        return Objects.equals(UNPAY.num, status);
    }
}
