//
//  ThreeLayerTemplate.swift
//  MVMCoreUI
//
//  Created by Scott Pfeil on 7/23/19.
//  Copyright © 2019 Verizon Wireless. All rights reserved.
//

import UIKit

@objcMembers open class ThreeLayerTemplate<TemplateModel: ThreeLayerPageTemplateModel>: ThreeLayerViewController, TemplateProtocol {

    //--------------------------------------------------
    // MARK: - Lifecycle
    //--------------------------------------------------
    
    open override func parsePageJSON() throws {
        try parseTemplate(json: loadObject?.pageJSON)
        try super.parsePageJSON()
    }
    
    open override func updateUI(for molecules: [MoleculeModelProtocol]? = nil) {
        topViewOutsideOfScroll = templateModel?.anchorHeader ?? false
        bottomViewOutsideOfScroll = templateModel?.anchorFooter ?? false
        super.updateUI(for: molecules)
    }

    open override func viewForTop() -> UIView? {
        guard let headerModel = templateModel?.header,
            let molecule = generateMoleculeView(from: headerModel)
            else { return  nil }
        
        return molecule
    }
    
    open override func viewForMiddle() -> UIView? {
        guard let middleModel = templateModel?.middle,
            let molecule = generateMoleculeView(from: middleModel)
            else { return  nil }
        
        return molecule
    }
    
    override open func viewForBottom() -> UIView? {
        guard let footerModel = templateModel?.footer,
            let molecule = generateMoleculeView(from: footerModel)
            else { return  nil }
        
        return molecule
    }
    
    //--------------------------------------------------
    // MARK: - Spacing
    //--------------------------------------------------
    
    open override func spaceBetweenTopAndMiddle() -> CGFloat? { 0 }
    
    open override func spaceBetweenMiddleAndBottom() -> CGFloat? { nil }
}
