package com.m2pool.lease.constant;

/**
 * @Description 普通订单状态
 * @Date 2025/9/3 16:19
 * @Author yyb
 */
public enum OrderStatus {
    PENDING_PAYMENT(0, "待支付"),
    FULLY_PAID(1, "(全部)已支付"),
    CANCELLED(2, "已取消"),
    AFTER_SALES(3, "售后状态"),
    REFUNDED(4, "已退款"),
    PAYMENT_TIMEOUT(5, "支付已超时"),
    PAYMENT_IN_PROGRESS(6, "支付中"),
    PARTIALLY_PAID(10, "部分已支付");

    private final int code;
    private final String description;

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

    /**
     * 获取订单状态编码
     * @return 订单状态编码
     */
    public int getCode() {
        return code;
    }

    /**
     * 获取订单状态描述
     * @return 订单状态描述
     */
    public String getDescription() {
        return description;
    }

    /**
     * 根据编码获取对应的订单状态枚举
     * @param code 订单状态编码
     * @return 订单状态枚举，如果未找到则返回 null
     */
    public static OrderStatus getByCode(int code) {
        for (OrderStatus status : OrderStatus.values()) {
            if (status.getCode() == code) {
                return status;
            }
        }
        return null;
    }
}
