package com.ruoyi.common.pay.tm.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 退款状态枚举
 * @author
 * 2024/09/24
 */
@Getter
@AllArgsConstructor
public enum RefundStatus {
    FAILED(0, "退款失败"),
    REFUNDED(1, "转入退款");

    private final int code;
    private final String description;

    /**
     * 根据状态码判断是否退款成功
     * @param code 状态码
     * @return 是否退款成功
     */
    public static boolean isSuccess(int code) {
        return REFUNDED.getCode() == code;
    }

    /**
     * 根据状态码获取对应的退款状态枚举
     * @param code 状态码
     * @return 对应的 RefundStatus 枚举
     */
    public static RefundStatus getByCode(int code) {
        for (RefundStatus status : RefundStatus.values()) {
            if (status.getCode() == code) {
                return status;
            }
        }
        return null;
    }
}
