// 🧪 P2PBox メッセージ型テスト
// 様々なデータ型のメッセージ送受信を検証

print("=== P2PBox Message Types Test ===")

// 通信世界とノードを作成
local world
world = new IntentBox()

local sender
local receiver
sender = new P2PBox("sender", world)
receiver = new P2PBox("receiver", world)

// 各種データ型のリスナーを登録
receiver.on("string_msg", "handle_string")
receiver.on("integer_msg", "handle_integer")
receiver.on("bool_msg", "handle_bool")
receiver.on("null_msg", "handle_null")
receiver.on("array_msg", "handle_array")
receiver.on("map_msg", "handle_map")

print("\n1. String message test")
sender.send("string_msg", "Hello, P2P World!", "receiver")

print("\n2. Integer message test")
sender.send("integer_msg", 42, "receiver")

print("\n3. Boolean message test")
sender.send("bool_msg", true, "receiver")

print("\n4. Null message test")
local nullValue
nullValue = new NullBox()
sender.send("null_msg", nullValue, "receiver")

print("\n5. Array message test (NOT IMPLEMENTED YET)")
// TODO: ArrayBox実装後に有効化
// local arr
// arr = new ArrayBox()
// arr.push("item1")
// arr.push("item2")
// sender.send("array_msg", arr, "receiver")

print("\n6. Map message test")
local data
data = new MapBox()
data.set("name", "Alice")
data.set("age", 25)
data.set("active", true)
sender.send("map_msg", data, "receiver")

print("\n7. Complex nested data test")
local complex
complex = new MapBox()
complex.set("type", "user_profile")

local details
details = new MapBox()
details.set("username", "alice123")
details.set("email", "alice@example.com")
complex.set("details", details)

sender.broadcast("complex_data", complex)

print("\n=== Message Types Test Complete ===")