package ru.dbotthepony.kstarbound.network.packets.clientbound

import it.unimi.dsi.fastutil.bytes.ByteArrayList
import ru.dbotthepony.kommons.io.readByteArray
import ru.dbotthepony.kommons.io.readMap
import ru.dbotthepony.kommons.io.readUUID
import ru.dbotthepony.kommons.io.writeByteArray
import ru.dbotthepony.kommons.io.writeMap
import ru.dbotthepony.kommons.io.writeUUID
import ru.dbotthepony.kstarbound.client.ClientConnection
import ru.dbotthepony.kstarbound.network.IClientPacket
import java.io.DataInputStream
import java.io.DataOutputStream
import java.util.UUID

class SystemWorldUpdatePacket(val objects: Map<UUID, ByteArrayList>, val ships: Map<UUID, ByteArrayList>) : IClientPacket {
	constructor(stream: DataInputStream, isLegacy: Boolean) : this(
		stream.readMap({ readUUID() }, { ByteArrayList.wrap(readByteArray()) }),
		stream.readMap({ readUUID() }, { ByteArrayList.wrap(readByteArray()) })
	)

	override fun write(stream: DataOutputStream, isLegacy: Boolean) {
		stream.writeMap(objects, { writeUUID(it) }, { writeByteArray(it.elements(), 0, it.size) })
		stream.writeMap(ships, { writeUUID(it) }, { writeByteArray(it.elements(), 0, it.size) })
	}

	override fun play(connection: ClientConnection) {
		TODO("Not yet implemented")
	}
}