package com.seer.teach.common.enums;

import java.util.Arrays;
import java.util.List;

/**
 * 订单状态枚举
 */
public enum OrderStatusEnum {

    PENDING_PAYMENT(0, "待付款"),
    PAID(1, "订单已付款，等待发货"),
    SHIPPED(2, "已发货,待用户确认收获"),
    PART_ORDER_SHIPPED(21, "部分订单已发货,待用户确认收获"),
    COMPLETED(3, "用户确认收货,已完成"),
    PART_COMPLETED(31, "用户确认部分订单收货"),
    CANCELED(4, "已取消"),
    PART_CANCELED(41, "部分订单已取消"),
    CLOSED(42, "订单已关闭"),
    CONFIRMED(50, "已确认"),
    REJECTED(60, "已驳回"),
    WAREHOUSE_SHIPPED(70, "仓库已发货"),
    DELETED(80, "已删除"),
    EXPIRED(90, "已过期");

    private final int code;
    private final String description;

    OrderStatusEnum(int code, String description) {
        this.code = code;
        this.description = description;
    }

    public int getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据code获取对应的枚举值
     * @param code 状态码
     *
     * @return 对应的枚举，如果不存在则返回null
     */
    public static OrderStatusEnum fromCode(int code) {
        for (OrderStatusEnum status : OrderStatusEnum.values()) {
            if (status.getCode() == code) {
                return status;
            }
        }
        return null;
    }

    public static List<Integer> getAppOrderStatusList() {
    	return Arrays.asList(OrderStatusEnum.PENDING_PAYMENT.getCode(),
                OrderStatusEnum.PAID.getCode(),
                OrderStatusEnum.SHIPPED.getCode(),
                OrderStatusEnum.COMPLETED.getCode(),
                OrderStatusEnum.PART_ORDER_SHIPPED.getCode(),
                OrderStatusEnum.PART_COMPLETED.getCode(),
                OrderStatusEnum.CANCELED.getCode(),
                OrderStatusEnum.PART_CANCELED.getCode(),
                OrderStatusEnum.CONFIRMED.getCode(),OrderStatusEnum.WAREHOUSE_SHIPPED.getCode());
    }
}
