//
//  DelegateObject.swift
//  MVMCoreUI
//
//  Created by Scott Pfeil on 4/12/19.
//  Copyright © 2019 Verizon Wireless. All rights reserved.
//

import UIKit


open class MVMCoreUIDelegateObject: DelegateObject {
    
    public weak var formHolderDelegate: FormHolderProtocol?
    public weak var buttonDelegate: ButtonDelegateProtocol?
    public weak var uiTextFieldDelegate: UITextFieldDelegate?
    public weak var uiTextViewDelegate: UITextViewDelegate?
    public weak var observingTextFieldDelegate: ObservingTextFieldDelegate?
    public weak var moleculeDelegate: MoleculeDelegateProtocol?
    public weak var alertDelegate: (MVMCoreAlertDelegateProtocol & NSObjectProtocol)?
    public weak var topAlertDelegate: (MVMCoreTopAlertDelegateProtocol & NSObjectProtocol)?

    open override func setAll(withDelegate delegate: Any) {
        super.setAll(withDelegate: delegate)
        formHolderDelegate = delegate as? FormHolderProtocol
        buttonDelegate = delegate as? ButtonDelegateProtocol
        uiTextFieldDelegate = delegate as? UITextFieldDelegate
        uiTextViewDelegate = delegate as? UITextViewDelegate
        observingTextFieldDelegate = delegate as? ObservingTextFieldDelegate
        moleculeDelegate = delegate as? MoleculeDelegateProtocol
        alertDelegate = delegate as? (MVMCoreAlertDelegateProtocol & NSObjectProtocol)
        topAlertDelegate = delegate as? (MVMCoreTopAlertDelegateProtocol & NSObjectProtocol)
    }
    
    class func delegateObject(from controller: MVMCoreViewControllerProtocol?) -> MVMCoreUIDelegateObject? {
        return controller?.delegateObject?() as? MVMCoreUIDelegateObject
    }
}
