import Foundation

/// OnlineState packet (0x05) — batch presence updates.
/// Matches TypeScript server: count (Int8) + array of (publicKey, boolean).
struct OnlineStateEntry {
    var publicKey: String
    var isOnline: Bool
}

struct PacketOnlineState: Packet {
    static let packetId = 0x05

    var entries: [OnlineStateEntry] = []

    func write(to stream: Stream) {
        // Client doesn't send this packet
    }

    mutating func read(from stream: Stream) {
        let count = max(stream.readInt8(), 0)
        var list: [OnlineStateEntry] = []
        for _ in 0..<count {
            let publicKey = stream.readString()
            let isOnline = stream.readBoolean()
            list.append(OnlineStateEntry(publicKey: publicKey, isOnline: isOnline))
        }
        entries = list
    }
}
