class ConfigManager {

	public static Hashtable<String, Object> getConfigurationsMap() {
		
		JsonArray propertySourcesArray = new JsonArray();
		Hashtable<String, Object> appPropsHashtable = new Hashtable<>();
		Hashtable<String, Object> rulePropsHashtable = new Hashtable<>();
		Hashtable<String, Object> configHashtable = new Hashtable<>();
		
		String configServerURL = CommonHttpUtils.getEnvironmentVariable(PacmanSdkConstants.CONFIG_SERVICE_URL);
		String configCredentials = CommonHttpUtils.getEnvironmentVariable(PacmanSdkConstants.CONFIG_CREDENTIALS);

		if (StringUtils.isNullOrEmpty(configServerURL) || StringUtils.isNullOrEmpty(configCredentials)) {
			logger.info(PacmanSdkConstants.MISSING_CONFIGURATION);
			throw new InvalidInputException(PacmanSdkConstants.MISSING_CONFIGURATION);
		}

		Map<String, Object> configCreds = CommonHttpUtils.getHeader(configCredentials);

		JsonObject configurationsFromPacmanTable = CommonHttpUtils.getConfigurationsFromConfigApi(configServerURL, configCreds);
		logger.info("Configured values {} ",configurationsFromPacmanTable);
		if (configurationsFromPacmanTable != null) {
			propertySourcesArray = configurationsFromPacmanTable.get("propertySources").getAsJsonArray();
		}

		
		if (propertySourcesArray.size() > 0) {
			for (int i = 0; i < propertySourcesArray.size(); i++) {
				JsonObject propertySource = (JsonObject) propertySourcesArray.get(i);

				if (propertySource.get(PacmanSdkConstants.NAME).toString().contains("application")) {
					JsonObject appProps = propertySource.get(PacmanSdkConstants.SOURCE).getAsJsonObject();
					appPropsHashtable = new Gson().fromJson(appProps,new TypeToken<Hashtable<String, Object>>() {}.getType());
				}
				if (propertySource.get(PacmanSdkConstants.NAME).toString().contains("rule")) {
					JsonObject ruleProps = propertySource.get(PacmanSdkConstants.SOURCE).getAsJsonObject();
					rulePropsHashtable = new Gson().fromJson(ruleProps,new TypeToken<Hashtable<String, Object>>() {}.getType());
				}
			}
		} else {
			logger.info(PacmanSdkConstants.MISSING_DB_CONFIGURATION);
			throw new InvalidInputException(PacmanSdkConstants.MISSING_DB_CONFIGURATION);
		}

		
		configHashtable.putAll(appPropsHashtable);
		configHashtable.putAll(rulePropsHashtable);
		return configHashtable;
	}

}