package com.crm.rely.backend.core.constant;

/**
 * 卡交易状态枚举
 * @author gao
 * @date 2025/11/4 16:29
 */
public enum CardTransacStatusEnum {
    AUTHORIZED("authorized", "已授权"),
    SUCCEED("succeed", "成功"),
    SUCCESS("success", "成功"),
    FAILED("failed", "失败"),
    FAIL("fail", "失败"),
    WAIT_PROCESS("wait_process", "待处理"),
    PROCESSING("processing", "处理中");

    private final String code;
    private final String description;

    CardTransacStatusEnum(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    public static CardTransacStatusEnum fromCode(String code) {
        if (code == null) {
            return null;
        }
        for (CardTransacStatusEnum status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        return null;
    }

    public static String matchCode(String code) {
        CardTransacStatusEnum statusEnum = fromCode(code);
        return statusEnum != null ? statusEnum.getDescription() : "";
    }
}
