//
//  PageBehaviorProtocol.swift
//  MVMCoreUI
//
//  Created by Kyle on 5/8/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//


public protocol PageBehaviorProtocol: ModelHandlerProtocol {
    
    /// Initializes the behavior with the model
    init(model: PageBehaviorModelProtocol, delegateObject: MVMCoreUIDelegateObject?)
}

/**
    Behavior conforming protocols. Behaviors will conform to one or more of these protocols to receive page lifecycle events that pertain to them.
 */

public protocol PageMoleculeTransformationBehavior: PageBehaviorProtocol {
    
    func onPageNew(rootMolecules: [MoleculeModelProtocol], _ delegateObject: MVMCoreUIDelegateObject)
}

public protocol PageVisibilityBehavior: PageBehaviorProtocol {
    
    func onPageShown(_ delegateObject: MVMCoreUIDelegateObject?)
    func onPageHidden(_ delegateObject: MVMCoreUIDelegateObject?)
}

public protocol PageScrolledBehavior: PageBehaviorProtocol {
    
    func pageScrolled(scrollView: UIScrollView, _ delegateObject: MVMCoreUIDelegateObject?)
}

public protocol PageLocalDataShareBehavior: PageBehaviorProtocol {
    
    func compileLocalPageDataForTransfer(_ delegateObject: MVMCoreUIDelegateObject) -> [AnyHashable: Any]
    func receiveLocalPageData(_ data:[AnyHashable: Any], _ delegateObject: MVMCoreUIDelegateObject)
}

public protocol PageCustomActionHandlerBehavior: PageBehaviorProtocol {
    
    /// - Parameters:
    ///   - actionType: The action type of the passed action model.
    ///   - information: information of the passed action model.
    ///   - additionalData: Additional information of the
    /// - Returns: Boolean determines if the action has been handled.
    func handleAction(type actionType: String?, information: [AnyHashable : Any]?, additionalData: [AnyHashable : Any]?) -> Bool
}

public extension MVMCoreUIDelegateObject {
    
    weak var behaviorTemplateDelegate: (PageBehaviorHandlerProtocol & NSObjectProtocol)? {
        (moleculeDelegate as? PageProtocol)?.pageModel as? (PageBehaviorHandlerProtocol & NSObjectProtocol)
    }
}
