package com.sckw.core.model.enums;

import org.springframework.util.ObjectUtils;

/**
 * @author lfdc
 * @version 1.0
 * @className GlobalTransactionalEnum
 * @description 全局事务枚举值
 * @company sckw
 * @date 2023-06-05 13:06:54
 */
public enum GlobalTransactionalEnum {
    /**
     * 默认全局事务
     */
    DEFAULT_TX_GROUP(1, "default_tx_group"),
    /**
     * 对应系统服务全局事务
     */
    SCKW_SYSTEM_SEATA_SERVICE_GROUP(2, "sckw-system-seata-service-group"),
    /**
     * 对应报表服务全局事务
     */
    SCKW_REPORT_SEATA_SERVICE_GROUP(3, "sckw-report-seata-service-group"),
    /**
     * 对应运输服务全局事务
     */
    SCKW_TRANSPORT_SEATA_SERVICE_GROUP(4, "sckw-transport-seata-service-group"),
    ;

    private final Integer code;
    private final String name;

    GlobalTransactionalEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }
    public Integer getCode() {
        return code;
    }
    public String getName() {
        return name;
    }
    public static String getValue(Integer code) {
        for (GlobalTransactionalEnum ele : GlobalTransactionalEnum.values()) {
            if (ele.getCode().equals(code)) {
                return ele.getName();
            }
        }
        return null;
    }
    String getGlobalTransactionalEnum(Integer code) {
        if (ObjectUtils.isEmpty(code)) {
            return null;
        }
        for (GlobalTransactionalEnum globalTransactionalEnum : GlobalTransactionalEnum.values()) {
            if (globalTransactionalEnum.getCode().equals(code)) {
                return globalTransactionalEnum.getName();
            }
        }
        return null;
    }
}
