//! Minimal demo of the Latticeon ECS: spawn entities, query, and run a system.
//!
//! Run with: `cargo run -p latticeon --example minimal_demo`

use latticeon::ecs::prelude::*;

#[derive(Debug, Clone, Component)]
struct Position(i32, i32);

#[derive(Debug, Clone, Component)]
struct Velocity(i32, i32);

fn main() {
    let mut universe = Universe::new();

    universe.spawn((Position(0, 0), Velocity(1, 0)));
    universe.spawn((Position(10, 5), Velocity(-1, 1)));
    universe.spawn((Position(3, 3), Velocity(0, 2)));

    println!("Query (read-only): all Position + Velocity");
    for (entity, pos, vel) in universe.query::<(&Position, &Velocity)>() {
        println!(
            "  {:?}: pos=({}, {}), vel=({}, {})",
            entity, pos.0, pos.1, vel.0, vel.1
        );
    }

    println!("\nQuery mut (for_each): add 1 to each Velocity.0");
    universe
        .query_mut::<(&Position, &mut Velocity)>()
        .for_each(|u, e| {
            if let Some(v) = u.get_mut::<Velocity>(e) {
                v.0 += 1;
            }
        });

    println!("\nAfter update:");
    for (entity, pos, vel) in universe.query::<(&Position, &Velocity)>() {
        println!(
            "  {:?}: pos=({}, {}), vel=({}, {})",
            entity, pos.0, pos.1, vel.0, vel.1
        );
    }

    println!("\nEntity count: {}", universe.entity_count());
}
