// Tests for mecha10_cli::sim::scene

use mecha10_cli::sim::scene::*;

#[test]
fn test_parse_simple_scene() {
    let content = r#"[gd_scene load_steps=2 format=3 uid="uid://test"]

[ext_resource type="Script" path="res://test.gd" id="1"]

[node name="Root" type="Node3D"]
script = ExtResource("1")
test_property = 42

[node name="Child" type="Node3D" parent="."]
position = Vector3(1, 2, 3)
"#;

    let scene = GodotScene::parse(content).unwrap();

    assert_eq!(scene.format_version, 3);
    assert_eq!(scene.load_steps, 2);
    assert_eq!(scene.uid, Some("uid://test".to_string()));
    assert_eq!(scene.ext_resources.len(), 1);
    assert_eq!(scene.nodes.len(), 2);

    assert_eq!(scene.nodes[0].name, "Root");
    assert_eq!(scene.nodes[0].node_type, "Node3D");
    assert_eq!(scene.nodes[1].name, "Child");
    assert_eq!(scene.nodes[1].parent, Some(".".to_string()));
}

#[test]
fn test_generate_scene() {
    let mut scene = GodotScene::new();
    scene.uid = Some("uid://test".to_string());

    let script_id = scene.add_ext_resource("Script", "res://test.gd");

    let mut root = SceneNode::new("Root", "Node3D");
    root.script = Some(format!("ExtResource(\"{}\")", script_id));
    root.set_property("test_property", "42");

    let child = SceneNode::new("Child", "Node3D").with_parent(".");

    scene.add_node(root);
    scene.add_node(child);

    let output = scene.to_string();

    assert!(output.contains("[gd_scene"));
    assert!(output.contains("load_steps=2"));
    assert!(output.contains("format=3"));
    assert!(output.contains("[ext_resource"));
    assert!(output.contains("[node name=\"Root\""));
    assert!(output.contains("[node name=\"Child\""));
}
