package com.rosetta.messenger.network

enum class DeviceResolveSolution(val value: Int) {
    ACCEPT(0),
    DECLINE(1);

    companion object {
        fun fromValue(value: Int): DeviceResolveSolution {
            return entries.firstOrNull { it.value == value } ?: DECLINE
        }
    }
}

class PacketDeviceResolve : Packet() {
    var deviceId: String = ""
    var solution: DeviceResolveSolution = DeviceResolveSolution.DECLINE

    override fun getPacketId(): Int = 0x18

    override fun receive(stream: Stream) {
        deviceId = stream.readString()
        solution = DeviceResolveSolution.fromValue(stream.readInt8())
    }

    override fun send(): Stream {
        val stream = Stream()
        stream.writeInt16(getPacketId())
        stream.writeString(deviceId)
        stream.writeInt8(solution.value)
        return stream
    }
}
