import Foundation

/// OnlineSubscribe packet (0x04) — subscribe to a user's online status updates.
/// Desktop parity: privateKey + int16(count) + publicKey[].
struct PacketOnlineSubscribe: Packet {
    static let packetId = 0x04

    var privateKey: String = ""
    var publicKeys: [String] = []

    func write(to stream: Stream) {
        stream.writeString(privateKey)
        stream.writeInt16(publicKeys.count)
        for key in publicKeys {
            stream.writeString(key)
        }
    }

    mutating func read(from stream: Stream) {
        privateKey = stream.readString()
        let count = stream.readInt16()
        publicKeys = (0..<count).map { _ in stream.readString() }
    }
}
