//! BigDataCloud — Phone & Email Verification Sample
//! Run: BIGDATACLOUD_API_KEY=your-key cargo run --example verification

use bigdatacloud::Client;

fn main() {
    let client = Client::from_environment().expect("Failed to create client");

    println!("=== Phone Validation ===");
    let phone = client.verification.validate_phone("+61412345678", "AU").unwrap();
    println!("Valid:         {}", phone.is_valid.unwrap_or(false));
    println!("E.164:         {}", phone.e164_format.as_deref().unwrap_or(""));
    println!("International: {}", phone.international_format.as_deref().unwrap_or(""));
    println!("National:      {}", phone.national_format.as_deref().unwrap_or(""));
    println!("Line Type:     {}", phone.line_type.as_deref().unwrap_or(""));
    if let Some(c) = &phone.country {
        println!("Country:       {} ({})", c.name.as_deref().unwrap_or(""), c.iso_alpha2.as_deref().unwrap_or(""));
    }

    println!("\n=== Phone Validation (invalid number) ===");
    let invalid = client.verification.validate_phone("+61199999999", "AU").unwrap();
    println!("Valid:     {}", invalid.is_valid.unwrap_or(false));
    println!("E.164:     {}", invalid.e164_format.as_deref().unwrap_or(""));
    println!("Line Type: {}", invalid.line_type.as_deref().unwrap_or(""));

    println!("\n=== Phone Validation by IP ===");
    let by_ip = client.verification.validate_phone_by_ip("+442012345678", "8.8.8.8").unwrap();
    println!("Valid:     {}", by_ip.is_valid.unwrap_or(false));
    println!("E.164:     {}", by_ip.e164_format.as_deref().unwrap_or(""));
    println!("Line Type: {}", by_ip.line_type.as_deref().unwrap_or(""));
    if let Some(c) = &by_ip.country {
        println!("Country:   {}", c.name.as_deref().unwrap_or(""));
    }

    println!("\n=== Email Verification ===");
    let email = client.verification.verify_email("user@bigdatacloud.com").unwrap();
    println!("Input:          {}", email.input_data.as_deref().unwrap_or(""));
    println!("Valid:          {}", email.is_valid.unwrap_or(false));
    println!("Syntax Valid:   {}", email.is_syntax_valid.unwrap_or(false));
    println!("Mail Server:    {}", email.is_mail_server_defined.unwrap_or(false));
    println!("Spammer Domain: {}", email.is_known_spammer_domain.unwrap_or(false));
    println!("Disposable:     {}", email.is_disposable.unwrap_or(false));

    println!("\n=== Email Verification (disposable) ===");
    let disp = client.verification.verify_email("test@mailinator.com").unwrap();
    println!("Valid:      {}", disp.is_valid.unwrap_or(false));
    println!("Disposable: {}", disp.is_disposable.unwrap_or(false));
}
