package ru.dbotthepony.kstarbound.defs

import ru.dbotthepony.kommons.io.readBinaryString
import ru.dbotthepony.kommons.io.writeBinaryString
import java.io.DataInputStream
import java.io.DataOutputStream

enum class ChatSendMode {
	BROADCAST, // Global
	LOCAL, // Planet (world)
	PARTY; // Party members only
}

data class MessageContext(val mode: Mode, val channelName: String = "") {
	constructor(stream: DataInputStream, isLegacy: Boolean) : this(Mode.entries[stream.readUnsignedByte()], stream.readBinaryString())

	fun write(stream: DataOutputStream, isLegacy: Boolean) {
		stream.writeByte(mode.ordinal)
		stream.writeBinaryString(channelName)
	}

	enum class Mode {
		LOCAL,
		PARTY,
		BROADCAST,
		WHISPER,
		COMMAND_RESULT,
		RADIO_MESSAGE,
		WORLD;
	}

	companion object {
		val LOCAL = MessageContext(Mode.LOCAL)
		val PARTY = MessageContext(Mode.PARTY)
		val BROADCAST = MessageContext(Mode.BROADCAST)
		val WHISPER = MessageContext(Mode.WHISPER)
		val COMMAND_RESULT = MessageContext(Mode.COMMAND_RESULT)
		val RADIO_MESSAGE = MessageContext(Mode.RADIO_MESSAGE)
		val WORLD = MessageContext(Mode.WORLD)
	}
}

// sender 0 is server
data class ChatMessage(val context: MessageContext, val sender: Int = 0, val senderNick: String = "Server", val portrait: String = "", val text: String)
