zenquirer 0.1.0

Interactive command-line questionnaires and prompts with async support
Documentation
use zenquirer::{Answers, macros::answers};

fn main() -> Result<(), zenquirer::Error> {
    // Demo 1: Basic numeric support in answers! macro
    println!("1. answers! macro with numbers:");
    let numeric_override_answers = answers! {
        "age" => 25,                           // i32 -> Number
        "height" => 175.5,                     // f64 -> Number
        "score" => 95.0_f32,                   // f32 -> Number
        "count" => 42_i64,                     // i64 -> Number
        "ratings" => vec!["4", "5", "3", "4"],         // Vec<&str> -> MultiSelected
        "prices" => vec!["19.99", "29.99", "39.99"], // Vec<&str> -> MultiSelected
        "name" => "John",                      // Still works - String
        "active" => true,                      // Still works - bool
    };

    println!("Numeric override answers: {numeric_override_answers:?}");

    // Demo 2: JSON serialization with numbers
    println!("\n2. JSON Serialization:");
    let json = serde_json::to_string_pretty(&numeric_override_answers)?;
    println!("Serialized JSON:\n{json}");

    // Demo 3: JSON deserialization with numeric values
    println!("\n3. JSON Deserialization with Numbers:");
    let json_with_numbers = r#"{
        "user_id": 12345,
        "balance": 1250.75,
        "scores": [85, 92, 78, 95],
        "percentages": [0.85, 0.92, 0.78],
        "username": "test_user",
        "is_admin": false
    }"#;

    println!("Input JSON with numbers:\n{json_with_numbers}");

    let parsed: Answers = serde_json::from_str(json_with_numbers)?;
    println!("Successfully parsed: {parsed:?}");

    // Demo 4: Roundtrip test (critical for data integrity)
    println!("\n4. Roundtrip Test:");
    let original = answers! {
        "temperature" => -5.5,
        "coordinates" => vec!["51.5074", "-0.1278"], // London lat/lng as strings
        "fibonacci" => vec!["1", "1", "2", "3", "5", "8"], // Fibonacci as strings
    };

    let json_out = serde_json::to_string(&original)?;
    let parsed_back: Answers = serde_json::from_str(&json_out)?;

    println!("Original: {original:?}");
    println!("JSON: {json_out}");
    println!("Parsed back: {parsed_back:?}");

    // Demo 5: Different numeric types
    println!("\n5. Different Numeric Types:");
    let type_demo = answers! {
        "small_int" => 42_i32,
        "big_int" => 9223372036854775807_i64,  // i64::MAX
        "float" => std::f32::consts::PI,
        "double" => std::f64::consts::E,
        "negative" => -273.15,
        "zero" => 0,
        "int_array" => vec!["1", "2", "3", "4", "5"],
        "float_array" => vec!["1.1", "2.2", "3.3"],
    };

    println!("Type demo: {type_demo:?}");
    let type_json = serde_json::to_string_pretty(&type_demo)?;
    println!("As JSON:\n{type_json}");

    // Demo 6: Edge cases
    println!("\n6. Edge Cases:");
    let edge_cases = answers! {
        "infinity" => f64::INFINITY,
        "neg_infinity" => f64::NEG_INFINITY,
        "very_small" => f64::EPSILON,
        "empty_numbers" => Vec::<String>::new(),
    };

    println!("Edge cases: {edge_cases:?}");

    // Demo 7: Manual Answer construction approaches
    println!("\n7. Manual Construction Examples:");

    // Using builder pattern
    use zenquirer::answer::{Answer, Value};
    let manual_builder = Answers::new()
        .with_answer("price", Answer::Number(Value::Single(99.99)))
        .with_answer(
            "quantities",
            Answer::Number(Value::Multiple(vec![1.0, 2.0, 3.0])),
        );

    // Using answers! macro
    let manual_macro = answers! {
        "price" => 99.99,
        "quantities" => vec!["1.0", "2.0", "3.0"],
    };

    println!("Builder pattern: {manual_builder:?}");
    println!("Macro syntax: {manual_macro:?}");

    println!("\nNumeric support demo completed!");
    println!("Key features:");
    println!("  - JSON with numbers deserializes correctly");
    println!("  - answers! macro supports all numeric types");
    println!("  - Automatic type conversion from common numeric types");
    println!("  - Full roundtrip serialization support");

    Ok(())
}