package com.sonic.lion.enums;

import org.springframework.lang.NonNull;


/**
 * @author: code
 * @date: 2025/05/07
 * @Description: 支付状态
 * @version: 1.0.0
 */
public enum TradeStatus {

    WAITPAY(1, "待付款"),

    PAID(2, "已付款"),

    PROCESSING(3, "处理中"),

    FINISHED(4, "交易成功"),

    CLOSED(5, "交易关闭"),

    REFUNDING(6, "退款中"),

    REFUNDED(7, "已退款"),
    ;

    private final int value;

    private final String desc;

    TradeStatus(Integer value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    public int getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }

    public static TradeStatus get(int value) {
        for (TradeStatus tradeStatus : values()) {
            if (tradeStatus.getValue() == value) {
                return tradeStatus;
            }
        }
        return null;
    }

    /**
     * 判断该交易状态是否是完成状态
     *
     * @return
     */
    public static boolean isComplete(@NonNull TradeStatus status) {
        return status == FINISHED || status == CLOSED || status == REFUNDING || status == REFUNDED;
    }

    public String getReponseString() {
        if (this.value == 1 || this.value == 3 || this.value == 6) {
            return "processing";
        } else if (this.value == 2 || this.value == 4 || this.value == 7) {
            return "success";
        } else if (this.value == 5) {
            return "failed";
        }
        return "processing";
    }
}
