use droidrun_core::driver::android::AndroidDriver;
use droidrun_core::driver::recording::RecordingDriver;
use droidrun_core::driver::DeviceDriver;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_subscriber::fmt()
.with_env_filter("info")
.with_target(false)
.init();
let mut inner = AndroidDriver::new(None, true);
inner.connect().await?;
println!("Connected to device");
let recorder = RecordingDriver::new(inner);
println!("\nPerforming actions...");
recorder.press_key(3).await?;
println!(" [recorded] press_key(3) — Home");
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
recorder.tap(540, 1200).await?;
println!(" [recorded] tap(540, 1200)");
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
recorder.swipe(540, 1800, 540, 600, 300).await?;
println!(" [recorded] swipe(540,1800 -> 540,600, 300ms)");
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
recorder.input_text("automation test", false).await?;
println!(" [recorded] input_text('automation test')");
let _screenshot = recorder.screenshot(true).await?;
println!(" [not recorded] screenshot (read-only)");
let _tree = recorder.get_ui_tree().await?;
println!(" [not recorded] get_ui_tree (read-only)");
recorder.press_key(3).await?;
println!(" [recorded] press_key(3) — Home");
let actions = recorder.recorded_actions();
println!("\n--- Recorded {} actions ---", actions.len());
let json = recorder.to_json()?;
println!("{json}");
tokio::fs::write("recorded_actions.json", &json).await?;
println!("\nSaved to recorded_actions.json");
recorder.clear_log();
println!("Log cleared ({} actions)", recorder.recorded_actions().len());
Ok(())
}