package com.haha.common.enums;

import lombok.Getter;

@Getter
public enum OrderStatus {

    PENDING_PAYMENT(0, "待支付"),
    COMPLETED(1, "已完成"),
    CANCELLED(2, "已取消"),
    CLOSED(3, "已关闭");

    private final int code;
    private final String description;

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

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

    public static String getDescription(Integer code) {
        OrderStatus status = fromCode(code);
        return status != null ? status.description : "未知";
    }

    public static boolean isCancelled(Integer code) {
        return code != null && code == CANCELLED.code;
    }

    public static boolean isPendingPayment(Integer code) {
        return code != null && code == PENDING_PAYMENT.code;
    }

    public static boolean isCompleted(Integer code) {
        return code != null && code == COMPLETED.code;
    }
}
