package ru.dbotthepony.kstarbound.network.packets.serverbound

import kotlinx.coroutines.launch
import ru.dbotthepony.kommons.io.readCollection
import ru.dbotthepony.kommons.io.readVector2i
import ru.dbotthepony.kommons.io.readVector3i
import ru.dbotthepony.kommons.io.writeCollection
import ru.dbotthepony.kommons.io.writeStruct2i
import ru.dbotthepony.kommons.io.writeStruct3i
import ru.dbotthepony.kommons.util.Either
import ru.dbotthepony.kommons.vector.Vector2i
import ru.dbotthepony.kommons.vector.Vector3i
import ru.dbotthepony.kstarbound.defs.world.CelestialParameters
import ru.dbotthepony.kstarbound.io.readEither
import ru.dbotthepony.kstarbound.io.writeEither
import ru.dbotthepony.kstarbound.network.IServerPacket
import ru.dbotthepony.kstarbound.network.packets.clientbound.CelestialResponsePacket
import ru.dbotthepony.kstarbound.server.ServerConnection
import ru.dbotthepony.kstarbound.world.UniversePos
import java.io.DataInputStream
import java.io.DataOutputStream

class CelestialRequestPacket(val requests: Collection<Either<Vector2i, Vector3i>>) : IServerPacket {
	constructor(stream: DataInputStream, isLegacy: Boolean) : this(stream.readCollection { readEither(isLegacy, { readVector2i() }, { readVector3i() }) })

	override fun write(stream: DataOutputStream, isLegacy: Boolean) {
		stream.writeCollection(requests) {
			writeEither(it, isLegacy, { writeStruct2i(it) }, { writeStruct3i(it) })
		}
	}

	override fun play(connection: ServerConnection) {
		connection.pushCelestialRequests(requests)

		connection.scope.launch {

		}
	}
}