import Foundation

// MARK: - DeviceResolveSolution

enum DeviceResolveSolution: Int {
    case accept = 0
    case decline = 1
}

// MARK: - PacketDeviceResolve (0x18)

/// Sent to accept or decline a pending device login request.
/// Also received from server when another device approves/declines this device.
struct PacketDeviceResolve: Packet {
    static let packetId = 0x18

    var deviceId: String = ""
    var solution: DeviceResolveSolution = .decline

    func write(to stream: Stream) {
        stream.writeString(deviceId)
        stream.writeInt8(solution.rawValue)
    }

    mutating func read(from stream: Stream) {
        deviceId = stream.readString()
        solution = DeviceResolveSolution(rawValue: stream.readInt8()) ?? .decline
    }
}
