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.readCollection
import ru.dbotthepony.kommons.io.readUUID
import ru.dbotthepony.kommons.io.readVector3i
import ru.dbotthepony.kommons.io.writeByteArray
import ru.dbotthepony.kommons.io.writeCollection
import ru.dbotthepony.kommons.io.writeStruct3i
import ru.dbotthepony.kommons.io.writeUUID
import ru.dbotthepony.kommons.vector.Vector3i
import ru.dbotthepony.kstarbound.client.ClientConnection
import ru.dbotthepony.kstarbound.network.IClientPacket
import ru.dbotthepony.kstarbound.world.SystemWorldLocation
import java.io.DataInputStream
import java.io.DataOutputStream
import java.util.UUID

class SystemWorldStartPacket(val location: Vector3i, val objects: Collection<ByteArrayList>, val ships: Collection<ByteArrayList>, val shipUUID: UUID, val shipLocation: SystemWorldLocation) : IClientPacket {
	constructor(stream: DataInputStream, isLegacy: Boolean) : this(
		stream.readVector3i(),
		stream.readCollection { ByteArrayList.wrap(readByteArray()) },
		stream.readCollection { ByteArrayList.wrap(readByteArray()) },
		stream.readUUID(),
		SystemWorldLocation.read(stream, isLegacy)
	)

	override fun write(stream: DataOutputStream, isLegacy: Boolean) {
		stream.writeStruct3i(location)
		stream.writeCollection(objects) { writeByteArray(it.elements(), 0, it.size) }
		stream.writeCollection(ships) { writeByteArray(it.elements(), 0, it.size) }
		stream.writeUUID(shipUUID)
		shipLocation.write(stream, isLegacy)
	}

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