package com.jeesharp.business.modules.finance.payorder.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 支付单状态：描述一次支付意图从创建到终态的生命周期。
 *
 * @author jeesharp
 * @since 2026-05-08
 */
@Getter
@AllArgsConstructor
public enum PayOrderStatusEnum {

    /**
     * 已落库，尚未拿到 prepay_id
     */
    INIT(0, "待预支付"),

    /**
     * 已调微信统一下单并写入 prepay_id
     */
    PREPAY_CREATED(1, "已生成预支付"),

    /**
     * 微信回调确认成功
     */
    SUCCESS(2, "支付成功"),

    /**
     * 用户重新发起支付或超时关单等
     */
    CLOSED(3, "已关闭"),

    /**
     * 渠道明确失败
     */
    FAIL(4, "失败");

    private final Integer value;
    private final String desc;

    public static PayOrderStatusEnum fromValue(Integer value) {
        if (value == null) {
            return null;
        }
        for (PayOrderStatusEnum e : values()) {
            if (e.value.equals(value)) {
                return e;
            }
        }
        return null;
    }

    public static String getDescByValue(Integer value) {
        PayOrderStatusEnum e = fromValue(value);
        return e != null ? e.getDesc() : "";
    }
}
