import Foundation

/// Action for push notification subscription.
enum PushNotificationAction: Int {
    case subscribe = 0
    case unsubscribe = 1
}

/// PushNotification packet (0x10) — registers or unregisters APNs/FCM token on server.
/// Sent after successful handshake to enable push notifications.
/// Cross-platform compatible with Android PacketPushNotification.
struct PacketPushNotification: Packet {
    static let packetId = 0x10

    var notificationsToken: String = ""
    var action: PushNotificationAction = .subscribe

    func write(to stream: Stream) {
        stream.writeString(notificationsToken)
        stream.writeInt8(action.rawValue)
    }

    mutating func read(from stream: Stream) {
        notificationsToken = stream.readString()
        let actionValue = stream.readInt8()
        action = PushNotificationAction(rawValue: actionValue) ?? .subscribe
    }
}
