use rust_shared::i18n::{
    init_translation_dictionary, 
    start_dictionary_update_task, 
    preload_translations_from_keys,
    trans, 
    Language, 
    Uniq
};
use std::time::Duration;

fn get_all_translation_keys() -> Vec<(String, Uniq, Language)> {
    vec![
        ("Hello", Uniq::Module("example"), Language::En),
        ("Привет", Uniq::Module("example"), Language::Ru),
        ("Goodbye", Uniq::Module("example"), Language::En),
        ("До свидания", Uniq::Module("example"), Language::Ru),
    ]
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // 1. Initialize the translation dictionary
    init_translation_dictionary()?;
    
    // 2. Optionally set a custom update interval (default is 5 minutes)
    rust_shared::i18n::set_update_interval(Duration::from_secs(10 * 60)); // 10 minutes
    
    // 3. Start the background update task
    start_dictionary_update_task()?;
    
    // 4. Preload translations (this is async and makes HTTP requests)
    preload_translations_from_keys(get_all_translation_keys).await?;
    
    // 5. Now you can use the trans() function synchronously
    let hello_ru = trans("Hello", Uniq::Module("example"), Language::En, &Language::Ru);
    let goodbye_ru = trans("Goodbye", Uniq::Module("example"), Language::En, &Language::Ru);
    
    println!("Hello in Russian: {}", hello_ru);
    println!("Goodbye in Russian: {}", goodbye_ru);
    
    // rust_shared::i18n::stop_dictionary_update_task();
    
    Ok(())
}
