package com.ylx.order.enums;

import lombok.Getter;

@Getter
public enum OrderStatusEnum {

    PENDING_PAYMENT(0, "待付款"),
    PENDING_DISPATCH(1, "待派单"),
    PENDING_ACCEPT(2, "待接单"),
    PENDING_SERVICE(3, "待服务"),
    IN_SERVICE(4, "服务中"),
    COMPLETED(5, "已完成"),
    CANCELLED(6, "已取消"),
    CLOSED(7, "已关闭"),
    REJECTED(8, "拒绝接单"),
    REFUND_SUCCESS(9, "退款成功");

    private final Integer code;
    private final String info;

    OrderStatusEnum(Integer code, String info) {
        this.code = code;
        this.info = info;
    }

    public static OrderStatusEnum fromCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (OrderStatusEnum status : values()) {
            if (status.code.equals(code)) {
                return status;
            }
        }
        return null;
    }

    public static String getInfoByCode(Integer code) {
        OrderStatusEnum status = fromCode(code);
        return status == null ? "未知" : status.getInfo();
    }
}
