//! Chinese Hanzi → Pinyin transliteration table.
//!
//! Context-free, single-reading mapping from the Unicode Unihan kMandarin field.
//! Covers the CJK Unified Ideographs block (U+4E00–U+9FFF).
//!
//! Pinyin is stripped of tone marks/numbers for ASCII output.
//! Where a character has multiple readings, the most common reading
//! (as determined by the Unicode Consortium) is used.
//!
//! Generated from Unicode Unihan database.
//! Character count: 20924
//!
//! PHF map generated by build.rs from src/tables/data/hanzi_pinyin.tsv.

// Hanzi → Pinyin (ASCII, no tones) — O(1) lookup via compile-time perfect hash.
include!(concat!(env!("OUT_DIR"), "/hanzi_pinyin_phf.rs"));

// Hanzi → Pinyin (toned, with diacritics) — O(1) lookup via compile-time perfect hash.
// Covers the most common ~2000 characters; falls through to toneless for the rest.
include!(concat!(env!("OUT_DIR"), "/hanzi_pinyin_toned_phf.rs"));

/// Look up pinyin for a Hanzi character.
#[inline]
pub fn lookup_hanzi(ch: char) -> Option<&'static str> {
    HANZI_PINYIN.get(&ch).copied()
}

/// Look up toned pinyin for a Hanzi character.
/// Returns diacritical pinyin (e.g., "běi") if available, otherwise falls through
/// to toneless pinyin (e.g., "bei").
#[inline]
pub fn lookup_hanzi_toned(ch: char) -> Option<&'static str> {
    HANZI_PINYIN_TONED
        .get(&ch)
        .copied()
        .or_else(|| HANZI_PINYIN.get(&ch).copied())
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_lookup_basic() {
        assert_eq!(lookup_hanzi('\u{4E00}'), Some("yi")); // 一
        assert_eq!(lookup_hanzi('\u{4EAC}'), Some("jing")); // 京
    }

    #[test]
    fn test_lookup_not_found() {
        assert!(lookup_hanzi('a').is_none());
    }
}
