//
//  VDSMoleculeViewProtocol.swift
//  MVMCoreUI
//
//  Created by Matt Bruce on 10/19/22.
//  Copyright © 2022 Verizon Wireless. All rights reserved.
//

import Foundation
import MVMCore

///-----------------------------------------------------------------------------
///MARK: -- VDSMoleculeViewProtocol (Contract between VDS -> Atomic)
///-----------------------------------------------------------------------------
public protocol VDSMoleculeViewProtocol: MoleculeViewProtocol, MVMCoreViewProtocol {
    associatedtype ViewModel: MoleculeModelProtocol
    var viewModel: ViewModel! { get set }
    var delegateObject: MVMCoreUIDelegateObject?  { get set }
    var additionalData: [AnyHashable: Any]?  { get set }
    func viewModelDidUpdate()
}

extension VDSMoleculeViewProtocol {

    public func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
        self.model = model
        guard let castedModel = model as? ViewModel else { return }
        self.delegateObject = delegateObject
        self.additionalData = additionalData
        viewModel = castedModel
        viewModelDidUpdate()
    }
    
    public func update(viewModel: ViewModel){
        set(with: viewModel, delegateObject, additionalData)
    }
}

