package com.m2pool.lease.constant;

/**
 * @Description 支付订单状态
 * @Date 2025/9/3 16:19
 * @Author yyb
 */
public enum PaymentStatus {
    PAYMENT_FAILED(0, "支付失败"),
    PAYMENT_SUCCESS_FULL(1, "支付成功--全部货款已支付"),
    PENDING_PAYMENT(2, "待支付"),
    PAYMENT_TIMEOUT(5, "支付已超时"),
    PAYMENT_IN_PROGRESS(6, "支付中"),
    PAYMENT_SUCCESS_PARTIAL(10, "支付成功--已支付部分货款");

    private final int code;
    private final String description;

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