use std::io;

use console::Emoji;
use console::style;
use crosswords::{read_dict_file, fuzzy_match};


fn main() {
    let lines = read_dict_file("dict/german.dic");

    println!("{}", style("Dictionary loaded!").bold());
    println!("{} Please insert query word, use '*' as a wildcard:", Emoji("🧩", "::"));

    loop {
        let mut user_input = String::new();
        io::stdin().read_line(&mut user_input).unwrap();
        user_input = String::from(user_input.trim());

        let matching_sorted_lines = fuzzy_match(&lines, &user_input);
        println!("Results: {:?}", matching_sorted_lines);
    }
}


#[test]
fn test_examples() {
    let lines = read_dict_file("dict/german.dic");

    assert!(fuzzy_match(&lines, &"initepeark".to_string()).contains(&"Pikanterie".to_string()));
    assert!(fuzzy_match(&lines, &"initepear*".to_string()).contains(&"Pikanterie".to_string()));
    assert!(fuzzy_match(&lines, &"initepea**".to_string()).contains(&"Pikanterie".to_string()));
    assert!(fuzzy_match(&lines, &"naehe".to_string()).contains(&"naehe".to_string()));
    assert!(fuzzy_match(&lines, &"na*he".to_string()).contains(&"naehe".to_string()));
}
