package com.example.demo.common;

import pers.jc.sql.CURD;

import java.util.HashMap;
import java.util.Map;

/**
 * 全局变量
 */
public class GlobalRoot {
    public static CURD db;

    public static void init()
    {
        initDatabase();
    }

    private static void initDatabase() {
        Map<String, Object> config = new HashMap<>();
        if (GlobalConfig.isLinux) {
            if (GlobalConfig.serverConfig.getServerIndex() == 0) {
                config.put("host", "10.206.16.5");
                config.put("port", 3306);
                config.put("username", "root");
                config.put("password", "SmartBow@2023_03_07+haha-1234567");
            } else if (GlobalConfig.serverConfig.getServerIndex() == 1) {
                config.put("host", "database-1.cv18q9jeluwr.us-east-1.rds.amazonaws.com");
                config.put("port", 3306);
                config.put("username", "admin");
                config.put("password", "smartbow+2023_03_07-haha+1234567");
            }
        } else {
            config.put("username", LocalTestConfig.instance.getDataBaseUsername());
            config.put("password", LocalTestConfig.instance.getDataBasePassword());
        }

        config.put("database", "smart_bow");
        GlobalRoot.db = new CURD(config);
    }
}
