package language;

import java.util.HashMap;
import java.util.Set;

import background.CommandManager;
import background.commands.Command;

public class Language {	
	public HashMap<String, String> dictionary;	
	public HashMap<String, String> reverseDictionary;
	public CommandManager commandManager;
	
	public Language(CommandManager cm) {
		commandManager = cm;
		dictionary = new HashMap<String, String>();
		reverseDictionary = new HashMap<String, String>();
		createDictionary();
	}
	
	public void addToDictionary(String word, String translation) {
		dictionary.put(word, translation);
		reverseDictionary.put(translation, word);
	}
		
	public String getReverse(String s) {
		if (reverseDictionary.containsKey(s)) return reverseDictionary.get(s);
		else return "";
	}
	
	public Command translate(String s) {										
		for (String keyword: dictionary.keySet()) {
			if (s.length() >= keyword.length()) {
				if (s.trim().startsWith(keyword)) {		
					/* priradujeme najdememu identifikatoru konkretny prikaz, takze potrebujeme zistit potrebne parametre... co si samotny prikaz zariadi neskor sam */
					Command c = getCommandByName(dictionary.get(keyword));					
					return c;
				}
			}
		}		

		if (!getRegexForUpdate().isEmpty() && s.matches(getRegexForUpdate())) {
			return getCommandByName("operacia");
		}

		
		return null;
	}
	
	public boolean checkForKeyword(String s) {
		for (String keyword: dictionary.keySet()) {						
			if (s.contains(keyword)) return true;
		}		
		return false;	
	}
	
	public Set<String> getKeywords() {
		return dictionary.keySet();	
	}
	
	public String getRegexForUpdate() {
		return "";
	}
	
	public String getStringForUpdate() {
		return "";
	}

	
	public Command getCommandByName(String name) {
		return null;		
	}
	
	public void createDictionary() {
		/* nastavene v jednotlivych jazykoch */
	}
	
	public void recognizeData(String s, Command C) {
	}	

	public String getEOLRegex() {
		return "";
	}

	
	
}
