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

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Map;

/**
 * 交易结果
 * @author wjh
 * 2024/9/10
 */
@Getter
@AllArgsConstructor
public enum SybTrxStatus {
    SUCCESS("0000", "交易成功"),
    PROCESSING("2000", "交易处理中"),
    NOT_EXIST("1001", "交易不存在"),
    REPEAT("3888", "流水号重复"),
    CHANNEL_MERCHANT_ERROR("3099", "渠道商户错误"),
    TRANSACTION_AMOUNT_LESS_THAN_SERVICE_CHARGE("3014", "交易金额小于应收手续费"),
    CHECK_REAL_NAME_INFO_FAILED("3031", "校验实名信息失败"),
    TRANSACTION_NOT_PAID("3088", "交易未支付"),
    TRANSACTION_REVERSED("3089", "撤销异常"),
    TRANSACTION_REVOKED("3050", "交易已被撤销");

    public static boolean isSuccess(String code) {
        return SUCCESS.getCode().equals(code);
    }

    public static boolean isSuccess(Map<String, String> result) {
        return result != null && isSuccess(result.get("trxstatus"));
    }

    public static SybTrxStatus getByCode(String code) {
        for (SybTrxStatus value : SybTrxStatus.values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        return null;
    }

    private final String code;
    private final String msg;

}
