import Foundation

// MARK: - SyncStatus

enum SyncStatus: Int {
    case notNeeded = 0
    case batchStart = 1
    case batchEnd = 2

    init(value: Int) {
        self = SyncStatus(rawValue: value) ?? .notNeeded
    }
}

// MARK: - PacketSync (0x19)

/// Sync packet — batch message synchronization.
struct PacketSync: Packet {
    static let packetId = 0x19

    var status: SyncStatus = .notNeeded
    var timestamp: Int64 = 0

    func write(to stream: Stream) {
        stream.writeInt8(status.rawValue)
        stream.writeInt64(timestamp)
    }

    mutating func read(from stream: Stream) {
        status = SyncStatus(value: stream.readInt8())
        timestamp = stream.readInt64()
    }
}
