//
//  GMFGOperationHandler.swift
//  MVM5G
//
//  Created by Jason Beck on 7/28/20.
//  Copyright © 2020 Kyle. All rights reserved.
//
import CoreBluetooth

enum GMFGOperationMode: String {
    case installation = "Installation"
    case operational = "Operational"
}

class GMFGOperationHandler: GMFGBLEHandlerProtocol {
    public func setOpMode(_ peripheral: CBPeripheral, _ characteristic: CBCharacteristic, mode: GMFGOperationMode, disableBLE: Bool = false) -> Bool {
        var requestValue: [String: Any] = ["ReceiverMode": mode.rawValue]
        if disableBLE {
            requestValue["DisableBLE"] = disableBLE
        }
        guard let data = convertToData(requestValue) else { return false }
        let writeType: CBCharacteristicWriteType = characteristic.properties.contains(.writeWithoutResponse) ? .withoutResponse : .withResponse
        peripheral.writeValue(data, for: characteristic, type: writeType)
        return true
    }
    
    func response(response: [String : Any]) {
        //This class does not currently respond to the VC, so this function is here only to satisfy protocol conformance
    }
    
    func deviceNotReady() {
        //This class does not currently respond to the VC, so this function is here only to satisfy protocol conformance
    }
}
