//
//  BluetoothDebuggableProtocol.swift
//  MVM5G
//
//  Created by Matt Bruce on 3/18/22.
//  Copyright © 2022 Kyle. All rights reserved.
//

import Foundation
import UIKit

//This is implemented on ViewControllers 
protocol BluetoothDebuggableProtocol: BluetoothDebuggerDelegate {
    associatedtype BluetoothPairType: MFFGHSBluetoothPair
    var view: UIView! { get set }
    var bluetoothPair: BluetoothPairType? { get set }
    var bluetoothDebugger: BluetoothDebugger? { get }
    var debuggerView: BluetoothDebuggerView? { get set}
    func addDebuggerView()
}

extension BluetoothDebuggableProtocol {
    var bluetoothDebugger: BluetoothDebugger? {
        return self.bluetoothPair?.bluetoothDebugger
    }
    
    func addDebuggerView(){
        guard GMFGTestScreenData.shared.visualDebugger else { return }
        debuggerView = BluetoothDebuggerView()
        if let debuggerView = debuggerView {
            debuggerView.translatesAutoresizingMaskIntoConstraints = false
            view.addSubview(debuggerView)
            debuggerView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
            debuggerView.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
            debuggerView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
            debuggerView.heightAnchor.constraint(equalToConstant: 400).isActive = true
        }
    }

    func bluetoothDebuggerUpdate(message: String){
        self.debuggerView?.text = message
    }
}
