import Foundation

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

/// Token type for push notification registration.
enum PushTokenType: Int {
    case fcm = 0
    case voipApns = 1
}

/// PushNotification packet (0x10) — registers or unregisters push token on server.
/// Cross-platform wire format parity (Server/Android):
///   writeString(token) + writeInt8(action) + writeInt8(tokenType) + writeString(deviceId)
struct PacketPushNotification: Packet {
    static let packetId = 0x10

    var notificationsToken: String = ""
    var action: PushNotificationAction = .subscribe
    var tokenType: PushTokenType = .fcm
    var deviceId: String = ""

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

    mutating func read(from stream: Stream) {
        notificationsToken = stream.readString()
        action = PushNotificationAction(rawValue: stream.readInt8()) ?? .subscribe
        tokenType = PushTokenType(rawValue: stream.readInt8()) ?? .fcm
        deviceId = stream.readString()
    }
}
