package data.Enums;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class WordLevelDefaultValues {
	public final static Logger logger = LogManager.getLogger(WordLevelDefaultValues.class);

	private static HashSet<String> suffixes;
	private static final String SUFFIXES_FILE = "/Lists/suffixes.txt";
	public static final int MIN_N_OF_CHARACTERS_LEFT_SUFFIX = 2;

	private static HashSet<String> prefixes;
	private static final String PREFIXES_FILE = "/Lists/prefixes.txt";
	public static final int MIN_N_OF_CHARACTERS_LEFT_PREFIX = 2;

	static {
		suffixes = new HashSet<>();
		suffixes = readFromFile(SUFFIXES_FILE);
		prefixes = new HashSet<>();
		prefixes = readFromFile(PREFIXES_FILE);
	}

	private static HashSet<String> readFromFile(String fileName) {
		Set<String> dictionary = new HashSet<>();

		try (InputStream is = WordLevelDefaultValues.class.getClass().getResourceAsStream(fileName)) {
			if (is != null) {
				// TODO: warn if !exists
				BufferedReader reader = new BufferedReader(new InputStreamReader(is));
				dictionary = reader.lines().collect(Collectors.toSet());
			}
		} catch (IOException e) {
			logger.error("Problem reading init dictionary", e);
		}

		return (HashSet<String>) dictionary;
	}

	public static HashSet<String> getSuffixes() {
		return suffixes;
	}

	public static HashSet<String> getPrefixes() {
		return prefixes;
	}
}
