package wa.server;

import zutil.db.DBConnection;
import zutil.osal.OSAbstractionLayer;
import zutil.osal.OSAbstractionLayer.OSType;

import java.io.File;

public class WAConstants {

    public static final String DB_FILE_NAME = "webadmin.db";
	public static final String DB_TABLE_PREFIX = "wa";
	public static DBConnection db;

	public static final String WA_ROOT_PATH_LINUX   = "/";
	public static final String WA_ROOT_PATH_WINDOWS = "C:\\webadmin\\";
	public static final String WA_BASE_CONFIG_PATH   = "etc/webadmin/";
    private static final File configPath;

	public static final String WA_SSL_CERT = "cert/server.crt";
	public static final String WA_SSL_KEY =  "cert/server.key";
	
	public static final String WA_CONFIG_BOUNDARY = "---- WebAdmin Configuration ----";
	
	
	static{
		OSAbstractionLayer os = OSAbstractionLayer.getInstance();

		if(os.getOSType() == OSType.Linux){
            configPath = new File(WA_ROOT_PATH_LINUX + WA_BASE_CONFIG_PATH);
		}
		else if(os.getOSType() == OSType.Windows){
            configPath = new File(WA_ROOT_PATH_WINDOWS + WA_BASE_CONFIG_PATH);
		}
        else {
            configPath = null;
        }

        if(configPath != null){
            try {
                db = new DBConnection(DBConnection.DBMS.SQLite, configPath.getAbsolutePath() + DB_FILE_NAME);
            } catch (Exception e) {
                e.printStackTrace();
                System.exit(1);
            }
        }
	}
	
	
	public static File getConfigFile(String name){
		return new File(configPath, name);
	}

	public static DBConnection getDB(){
		return db;
	}
}
