package com.rosetta.messenger.network

/**
 * Push Notification Action
 */
enum class PushNotificationAction(val value: Int) {
    SUBSCRIBE(0),
    UNSUBSCRIBE(1)
}

/**
 * Push Notification packet (ID: 0x10)
 * Отправка FCM/APNS токена на сервер для push-уведомлений (новый формат)
 * Совместим с React Native версией
 */
class PacketPushNotification : Packet() {
    var notificationsToken: String = ""
    var action: PushNotificationAction = PushNotificationAction.SUBSCRIBE

    override fun getPacketId(): Int = 0x10

    override fun receive(stream: Stream) {
        notificationsToken = stream.readString()
        action = when (stream.readInt8()) {
            1 -> PushNotificationAction.UNSUBSCRIBE
            else -> PushNotificationAction.SUBSCRIBE
        }
    }

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