use memkit_co::{MkCoordinator, CoordinatorConfig, BufferingMode};
use memkit_gpu::{DummyBackend, MkBufferUsage, MkMemoryType};

#[test]
fn test_coordinator_lifecyle() {
    let backend = DummyBackend::new();
    let config = CoordinatorConfig::default();
    let mut coordinator = MkCoordinator::new(backend, config);
    
    // Frame 1
    coordinator.begin_frame();
    {
        // Allocate frame data (internally uses memkit arena)
        let _data = coordinator.frame_alloc::<u32>();
    }
    coordinator.end_frame().unwrap();
    
    // Frame 2
    coordinator.begin_frame();
    coordinator.end_frame().unwrap();
}

#[test]
fn test_staging_pool() {
    let backend = DummyBackend::new();
    let config = CoordinatorConfig {
        staging_pool_size: 4,
        staging_buffer_size: 1024,
        ..CoordinatorConfig::default()
    };
    
    let mut coordinator = MkCoordinator::new(backend, config);
    
    coordinator.begin_frame();
    
    // Acquire staging buffer
    let staging = coordinator.acquire_staging(100).unwrap();
    assert!(staging.size() >= 100);
    
    // Manually release (usually handled by transfer mechanism)
    coordinator.release_staging(staging);
    
    coordinator.end_frame().unwrap();
}

#[test]
fn test_double_buffering() {
    let backend = DummyBackend::new();
    let config = CoordinatorConfig {
        buffering: BufferingMode::Double,
        ..CoordinatorConfig::default()
    };
    
    let mut coordinator = MkCoordinator::new(backend, config);
    
    // Verify frames rotate
    for _ in 0..10 {
        coordinator.begin_frame();
        coordinator.end_frame().unwrap();
    }
}
