//
//  ModalSectionListTemplateModel.swift
//  MVMCoreUI
//
//  Created by Scott Pfeil on 10/8/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//
import MVMCore

@objcMembers public class ModalSectionListTemplateModel: SectionListTemplateModel {
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    
    public override class var identifier: String { "modalSectionList" }
    public var closeAction: ActionModelProtocol?
    
    //--------------------------------------------------
    // MARK: - Initializer
    //--------------------------------------------------
    
    public override init(with sections: [SectionModel], pageType: String, molecules: [ListItemModelProtocol & MoleculeModelProtocol], screenHeading: String?) {
        super.init(with: sections, pageType: pageType, molecules: molecules, screenHeading: screenHeading)
    }
    
    //--------------------------------------------------
    // MARK: - Keys
    //--------------------------------------------------
    
    private enum CodingKeys: String, CodingKey {
        case closeAction
    }
    
    //--------------------------------------------------
    // MARK: - Init
    //--------------------------------------------------
    
    required public init(from decoder: Decoder) throws {
        let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
        closeAction = try typeContainer.decodeModelIfPresent(codingKey: .closeAction)
        try super.init(from: decoder)
    }
    
    //--------------------------------------------------
    // MARK: - Codec
    //--------------------------------------------------
    
    public override func encode(to encoder: Encoder) throws {
        try super.encode(to: encoder)
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encodeModelIfPresent(closeAction, forKey: .closeAction)
    }
}
