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

import UIKit


@objcMembers open class MoleculeTableViewCell: TableViewCell {
    //--------------------------------------------------
    // MARK: - MoleculeViewProtocol
    //--------------------------------------------------
    
    public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
        
        guard let castModel = model as? MoleculeListItemModel else {
            super.set(with: model, delegateObject, additionalData)
            return
        }
        
        if molecule != nil {
            molecule?.set(with: castModel.molecule, delegateObject, additionalData)
        } else if let moleculeView = ModelRegistry.createMolecule(castModel.molecule, delegateObject: delegateObject, additionalData: additionalData) {
            addMolecule(moleculeView)
        }
        super.set(with: model, delegateObject, additionalData)
    }

    public override class func nameForReuse(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> String? {
        MoleculeContainer.nameForReuse(with: model, delegateObject)
    }
    
    public override class func requiredModules(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject?>?) -> [String]? {
        MoleculeContainer.requiredModules(with: model, delegateObject, error: error)
    }
    
    public override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
        MoleculeContainer.estimatedHeight(with: model, delegateObject) ?? 80
    }
}
