use archetype_asset::cache::pool::AssetMemoryPool;
use archetype_asset::model::{Mesh, PrimitiveType};
use archetype_asset::renderer::Vertex;

#[test]
fn test_mesh_pool_integration() {
    let pool = AssetMemoryPool::new();
    assert_eq!(pool.mesh_data_count(), 0);

    let vertices = vec![Vertex {
        position: [0.0, 0.0, 0.0],
        normal: [0.0, 1.0, 0.0],
        uv: [0.0, 0.0],
        tangent: [1.0, 0.0, 0.0, 1.0],
        color: [1.0, 1.0, 1.0, 1.0],
    }];
    let indices = vec![0];

    // Create a mesh, which should allocate from the pool
    let mesh = Mesh::new(
        Some("test".to_string()),
        PrimitiveType::Points,
        vertices,
        indices,
        None,
        &pool,
    );

    // Verify pool count increased
    assert_eq!(pool.mesh_data_count(), 1);

    // Verify mesh data is accessible
    assert_eq!(mesh.vertex_count(), 1);

    // Create another mesh
    let _mesh2 = Mesh::new(
        Some("test2".to_string()),
        PrimitiveType::Points,
        vec![],
        vec![],
        None,
        &pool,
    );
    assert_eq!(pool.mesh_data_count(), 2);

    drop(mesh);
    // Note: Pool count in this implementation is a monotonic counter of total allocations,
    // it doesn't decrease on drop (checking implementation details).
    // If it *tracked* live count, strict check would be possible.
    // Based on pool.rs: `self.mesh_data_count.fetch_add(1, Ordering::SeqCst);`
    // It's strictly cumulative.
}
