package pl.polgrabia.demos.crackingcodeinterview.t16x20;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.file.Paths;

public class Program {
    private static final Logger logger = LoggerFactory.getLogger(Program.class);
    public static void main(String[] args) {
        if (args.length != 1) {
            logger.error("Usage: java Program <dictionary_path>");
            System.exit(1);
            return;
        }

        var wordDictionaryPath = args[0];
        var rstTree = new RstTreeLoader(Paths.get(wordDictionaryPath)).load();
        // test for rst tree
        String w = "abadia"; // exists
        // String w = "asdadsadadlosdaladsad"; // doesn't exists
        // String w = "abcdefg"; // doesn't exists
        logger.info("Looking for word: {} - {}", w, rstTree.contains(w));
        String prefix = "ark";
        // logger.info("Searching by prefix: {}", prefix);
        rstTree.dfsByPrefix(prefix, (it) -> logger.info("Found word by prefix ({}) - {}", prefix, it));
        var t9Lookup = new T9Lookup(rstTree);
        int code = 8733;
        t9Lookup.lookupByCode(code, (it) -> logger.info("Found word by code ({}) - {}", code, it));

    }

}
