//
//  StackPageTemplate.swift
//  MVMCoreUI
//
//  Created by Suresh, Kamlesh on 11/22/19.
//  Copyright © 2019 Verizon Wireless. All rights reserved.
//


@objcMembers public class StackPageTemplateModel: ThreeLayerModelBase {
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    
    public override class var identifier: String { "stack" }
    public var moleculeStack: StackModel
    
    public override var rootMolecules: [MoleculeModelProtocol] {
        [navigationBar, header, moleculeStack, footer].compactMap { $0 }
    }
    
    //--------------------------------------------------
    // MARK: - Init
    //--------------------------------------------------
    
    public init(pageType: String, moleculeStack: StackModel) {
        self.moleculeStack = moleculeStack
        super.init(pageType: pageType)
    }
    
    //--------------------------------------------------
    // MARK: - Keys
    //--------------------------------------------------
    
    private enum CodingKeys: String, CodingKey {
        case stack
    }
    
    //--------------------------------------------------
    // MARK: - Codec
    //--------------------------------------------------
    
    required public init(from decoder: Decoder) throws {
        let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
        moleculeStack = try typeContainer.decode(StackModel.self, forKey: .stack)
        try super.init(from: decoder)
    }
    
    public override func encode(to encoder: Encoder) throws {
        try super.encode(to: encoder)
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(moleculeStack, forKey: .stack)
    }
}
