package data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Objects;

/*
Created for when words are sorted by multiple keys, i.e. not just lemmas but lemmas and msd simultaneously.
*/
public interface Word {
	String getW1();
	default String getW2(){ return null; }
	default String getW3(){ return null; }
	default String getW4(){ return null; }

	default String get(ArrayList<CalculateFor> wordParts, CalculateFor cf){
		if (wordParts.size() > 0 && wordParts.get(0).equals(cf))
			return getW1();
		if (wordParts.size() > 1 && wordParts.get(1).equals(cf))
			return getW2();
		if (wordParts.size() > 2 && wordParts.get(2).equals(cf))
			return getW3();
		if (wordParts.size() > 3 && wordParts.get(3).equals(cf))
			return getW4();
		return null;
	}

	default String getWord(ArrayList<CalculateFor> wordParts){
		String w = get(wordParts, CalculateFor.WORD);
		if (w == null){
			return get(wordParts, CalculateFor.LOWERCASE_WORD);
		}
		return w;
	}

	default String getLemma(ArrayList<CalculateFor> wordParts){
		return get(wordParts, CalculateFor.LEMMA);
	}

	default String getMsd(ArrayList<CalculateFor> wordParts){
		return get(wordParts, CalculateFor.MORPHOSYNTACTIC_SPECS);
	}

	default String getNormalizedWord(ArrayList<CalculateFor> wordParts){
		return get(wordParts, CalculateFor.NORMALIZED_WORD);
	}

	void setW1(String w);
	default void setW2(String w){}
	default void setW3(String w){}
	default void setW4(String w){}

	default void set(String w, ArrayList<CalculateFor> wordParts, CalculateFor cf){
		switch(wordParts.indexOf(cf)){
			case 0:
				setW1(w);
				break;
			case 1:
				setW2(w);
				break;
			case 2:
				setW3(w);
				break;
			case 3:
				setW4(w);
				break;
		}
	}

	default void setLemma(String w, ArrayList<CalculateFor> wordParts){
		set(w, wordParts, CalculateFor.LEMMA);
	}

	default void setMsd(String w, ArrayList<CalculateFor> wordParts){
		set(w, wordParts, CalculateFor.MORPHOSYNTACTIC_SPECS);
	}

	default void setNormalizedWord(String w, ArrayList<CalculateFor> wordParts){
		set(w, wordParts, CalculateFor.NORMALIZED_WORD);
	}


	default String getCVVWord(ArrayList<CalculateFor> cf) {
		return covertToCvv(getWord(cf));
	}

	default String getCVVLemma(ArrayList<CalculateFor> cf) {
		return covertToCvv(getLemma(cf));
	}

	default String covertToCvv(String s) {
		final HashSet<Character> VOWELS = new HashSet<>(Arrays.asList('a', 'e', 'i', 'o', 'u'));

		char[] StringCA = s.toCharArray();

		for (int i = 0; i < StringCA.length; i++) {
			StringCA[i] = VOWELS.contains(StringCA[i]) ? 'V' : 'C';
		}

		return new String(StringCA);
	}

	default String getForCf(CalculateFor calculateFor, boolean cvv, ArrayList<CalculateFor> cf) {
		String returnValue = "";

		if (cvv) {
			returnValue = (calculateFor == CalculateFor.WORD || calculateFor == CalculateFor.LOWERCASE_WORD) ? getCVVWord(cf) : getCVVLemma(cf);
		} else {
			if (calculateFor == CalculateFor.WORD || calculateFor == CalculateFor.LOWERCASE_WORD){
				returnValue = getWord(cf);
			} else if (calculateFor == CalculateFor.LEMMA) {
				returnValue = getLemma(cf);
			} else if (calculateFor == CalculateFor.NORMALIZED_WORD){
				returnValue = getNormalizedWord(cf);
			}
//			returnValue = (calculateFor == CalculateFor.WORD || calculateFor == CalculateFor.LOWERCASE_WORD) ? getWord(cf) : getLemma(cf);
		}

		return returnValue;
	}
}
