package com.github.aureliano.achmed;

import java.util.Locale;

import org.apache.log4j.Logger;

import com.github.aureliano.achmed.idiom.LanguageCode;
import com.github.aureliano.achmed.idiom.LanguageSingleton;
import com.github.aureliano.achmed.os.IOperatingSystem;
import com.github.aureliano.achmed.os.OperatingSystemFactory;

public final class AppConfiguration {

	private static final Logger logger = Logger.getLogger(AppConfiguration.class);
	
	private static AppConfiguration instance;
	
	private LanguageCode language;
	private IOperatingSystem operatingSystem;
	
	private AppConfiguration() {
		this.applyConfiguration();
	}
	
	public static AppConfiguration instance() {
		if (instance == null) {
			instance = new AppConfiguration();
		}
		
		return instance;
	}
	
	public void applyConfiguration() {
		logger.info("Apply core configuration.");
		
		this.configureLocale();
		LanguageSingleton.instance().setDefaultLanguageCode(this.language);
		
		this.resolveOperatingSystem();
	}
	
	public LanguageCode getLanguage() {
		return language;
	}
	
	public IOperatingSystem getOperatingSystem() {
		return operatingSystem;
	}
	
	private void resolveOperatingSystem() {
		logger.info("Resolve operating system.");
		
		this.operatingSystem = OperatingSystemFactory.currentOperatingSystem();
		logger.info("Operating System: " + this.operatingSystem.getOperatingSystem());
		logger.info("Operating System family: " + this.operatingSystem.getOperatingSystemFamily());
	}
	
	private void configureLocale() {
		logger.info("Configuring default locale.");
		
		Locale locale = Locale.getDefault();
		String code = locale.getLanguage() + "_" + locale.getCountry();
		
		logger.info(String.format(
				"Using default locale to %s with language %s (%s).",
				locale.getDisplayCountry(),
				locale.getDisplayLanguage(),
				code
			)
		);
		
		this.language = LanguageCode.valueOf(code.toUpperCase());
	}
}
@@ -90,16 +90,72 @@
 ogger;%0A%0A
+import com.github.aureliano.achmed.helper.StringHelper;%0A
 import c
@@ -1838,24 +1838,48 @@
 ntry(),%0A%09%09%09%09
+StringHelper.capitalize(
 locale.getDi
@@ -1893,16 +1893,17 @@
 nguage()
+)
 ,%0A%09%09%09%09co

Capitalize idiom name.