use super::trienode::TrieKey;

pub trait KeyChecker<KEY>
where
    KEY: TrieKey,
{
    fn check(k1: Option<KEY>, k2: Option<KEY>) -> bool;
}

pub struct CaseInsensitiveKeyChecker {}

impl KeyChecker<char> for CaseInsensitiveKeyChecker {
    fn check(k1: Option<char>, k2: Option<char>) -> bool {
        k1.zip(k2)
            .map(|(v1, v2)| v1.to_lowercase().next() == v2.to_lowercase().next())
            .unwrap_or_else(|| k1 == k2)
    }
}

pub struct CaseSensitiveKeyChecker {}

impl KeyChecker<char> for CaseSensitiveKeyChecker {
    fn check(k1: Option<char>, k2: Option<char>) -> bool {
        k1 == k2
    }
}
