package com.seer.teach.common.enums;

/**
 * 物流状态枚举类
 */
public enum ShippingStatusEnum {

    NOT_SHIPPED(0, "未发货"),
    SHIPPED(1, "已发货"),
    PART_SHIPPED(11, "部分订单已发货"),
    SIGNED(2, "已签收"),
    PART_SIGNED(22, "部分订单已签收"),
    SIGNED_EXCEPTION(21, "发货异常");

    private final int code;
    private final String description;

    ShippingStatusEnum(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 ShippingStatusEnum fromCode(int code) {
        for (ShippingStatusEnum status : ShippingStatusEnum.values()) {
            if (status.getCode() == code) {
                return status;
            }
        }
        return null;
    }
}
