#!/usr/bin/env herodo
// VM Control Demo
// Demonstrates all VM control operations including reset

// ============================================================================
// SETUP REQUIRED: Edit these paths for your environment
// ============================================================================
let kernel_path = "/path/to/vmlinuz";
let initramfs_path = "/path/to/initrd.img";
let disk_path = "/path/to/disk.img";
// ============================================================================

print("╔════════════════════════════════════════════════════════════╗");
print("║  VM Control Demo                                           ║");
print("╚════════════════════════════════════════════════════════════╝");
print("");

// Initialize runtime
let runtime = RuntimeBuilder()
    .ch_path("/usr/local/bin/cloud-hypervisor")
    .api_socket("/tmp/ch-control.sock");

if !init_runtime(runtime) {
    print("❌ Failed to initialize runtime. Exiting.");
    return;
}
print("✓ Runtime initialized");
print("");

// Create VM
let vm = VMBuilder()
    .kernel(kernel_path)
    .initramfs(initramfs_path)
    .cmdline("console=ttyS0 root=/dev/vda1")
    .cpus(2)
    .memory(2048)
    .virtio_blk(disk_path, false)
    .serial("tty")
    .build();

print("Creating VM...");
let handle = create_vm(vm);
print("✓ VM created: " + handle.id);
print("");

// Start VM
print("▶️  Starting VM...");
start_vm(handle);
print("✓ VM started");
let status = get_vm_status();
print("   Status: " + status);
print("");

sleep(3000);

// Pause VM
print("⏸️  Pausing VM...");
pause_vm(handle);
print("✓ VM paused");
let status = get_vm_status();
print("   Status: " + status);
print("");

sleep(2000);

// Resume VM
print("▶️  Resuming VM...");
resume_vm(handle);
print("✓ VM resumed");
let status = get_vm_status();
print("   Status: " + status);
print("");

sleep(3000);

// Reset VM (reboot)
print("🔄 Resetting VM (reboot)...");
reset_vm(handle);
print("✓ VM reset");
let status_after_reset = get_vm_status();
print("   Status: " + status_after_reset);
print("");

sleep(5000);

// Stop VM
print("⏹️  Stopping VM...");
stop_vm(handle);
print("✓ VM stopped");
print("");

print("╔════════════════════════════════════════════════════════════╗");
print("║  VM Control Demo Complete                                 ║");
print("╚════════════════════════════════════════════════════════════╝");
