// 🧪 Zero-copy Detection Simple Test - Phase 10 Feature Verification
// Testing BufferBox.is_shared_with() and share_reference() APIs

static box Main {
    init { console }
    
    main() {
        me.console = new ConsoleBox()
        me.console.log("🧪 Phase 10: Zero-copy Detection Test")
        
        // Test 1: Create two separate buffers (should NOT be shared)
        me.console.log("\n=== Test 1: Separate buffers ===")
        local buffer1 = new BufferBox()
        local buffer2 = new BufferBox()
        
        buffer1.write("Hello World")
        buffer2.write("Different Data")
        
        local is_shared_separate = buffer1.is_shared_with(buffer2)
        me.console.log("Separate buffers shared: " + is_shared_separate)
        
        // Test 2: Create shared reference (SHOULD be shared)  
        me.console.log("\n=== Test 2: Shared reference ===")
        local buffer3 = new BufferBox()
        buffer3.write("Shared Data Test")
        
        local shared_buffer = buffer3.share_reference(buffer3)
        local is_shared_ref = buffer3.is_shared_with(shared_buffer)
        me.console.log("Shared reference detection: " + is_shared_ref)
        
        // Test 3: Memory footprint monitoring
        me.console.log("\n=== Test 3: Memory footprint ===")
        local memory_size = buffer3.memory_footprint()
        me.console.log("Buffer3 memory footprint: " + memory_size + " bytes")
        
        // Test 4: Zero-copy behavior simulation
        me.console.log("\n=== Test 4: Zero-copy simulation ===")
        local original_buffer = new BufferBox()
        original_buffer.write("Large data for zero-copy test")
        
        local zero_copy_buffer = original_buffer.share_reference(original_buffer)
        local zero_copy_result = original_buffer.is_shared_with(zero_copy_buffer)
        
        if (zero_copy_result.toString() == "true") {
            me.console.log("✅ Zero-copy achieved! Memory sharing successful")
        } else {
            me.console.log("❌ Zero-copy failed! Unnecessary data copying detected")
        }
        
        me.console.log("\n🎉 Phase 10 Zero-copy API Test Complete!")
        return "Zero-copy test finished"
    }
}