//
//  PageBehaviorHandlerModelProtocol.swift
//  MVMCoreUI
//
//  Created by Scott Pfeil on 3/29/21.
//  Copyright © 2021 Verizon Wireless. All rights reserved.
//

public protocol PageBehaviorHandlerModelProtocol {
    var behaviors: [PageBehaviorModelProtocol]? { get set }
}

public extension PageBehaviorHandlerModelProtocol {
    
    /// Adds the behavior model to the behaviors if possible.
    mutating func add(behavior: PageBehaviorModelProtocol) {
        var newBehaviors = behaviors ?? []
        guard !behavior.shouldAllowMultipleInstances,
              !newBehaviors.contains(where: { $0.behaviorName == behavior.behaviorName
              }) else { return }
        
        newBehaviors.append(behavior)
        self.behaviors = newBehaviors
    }
}
