package com.jay.monitor.data.server.utils;

import com.jay.monitor.data.server.config.props.MonitorProperties;
import com.jay.monitor.data.server.enums.DataSplitType;
import com.jay.monitor.data.server.enums.StoreType;

import java.util.Map;

/**
 * @Module 工具类
 * @Description 规范化监控属性获取
 * @Author liukaixiong
 * @Date 2020/11/5 20:02
 */
public class MonitorPropertiesUtil {

    public static Map<String, DataSplitType> getMysqlTableRuleMap(MonitorProperties properties) {
        return getTableRuleMap(properties, StoreType.MYSQL);
    }

    public static Map<String, DataSplitType> getTableRuleMap(MonitorProperties properties, StoreType storeType) {
        Map<StoreType, MonitorProperties.StoreInfo> storeInfoMap = properties.getStoreInfo();

        if (properties.getStoreInfo() == null) {
            return null;
        }

        MonitorProperties.StoreInfo storeInfo = storeInfoMap.get(storeType);

        if (storeInfo == null) {
            return null;
        }

        Map<String, DataSplitType> tableRule = storeInfo.getTableRule();
        return tableRule;
    }
}
