package com.rosetta.messenger.network

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

/**
 * Token type for push notifications.
 */
enum class PushTokenType(val value: Int) {
    FCM(0),
    VOIP_APNS(1)
}

/**
 * Push Notification packet (ID: 0x10)
 * Отправка FCM/APNS токена на сервер для push-уведомлений
 * Передаёт tokenType (fcm/voip) и deviceId
 */
class PacketPushNotification : Packet() {
    var notificationsToken: String = ""
    var action: PushNotificationAction = PushNotificationAction.SUBSCRIBE
    var tokenType: PushTokenType = PushTokenType.FCM
    var deviceId: String = ""

    override fun getPacketId(): Int = 0x10

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

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