//
//  ListOneColumnFullWidthTextDividerSubsectionModel.swift
//  MVMCoreUI
//
//  Created by Dhamodaram Nandi on 09/03/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//

import Foundation


public class ListOneColumnFullWidthTextDividerSubsectionModel: ListItemModel, MoleculeModelProtocol {
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    
    public static var identifier: String = "list1CTxtDiv3"
    public var headline: LabelModel
    public var body: LabelModel?
    
    //--------------------------------------------------
    // MARK: - Initializer
    //--------------------------------------------------
    
    public init(headline: LabelModel, body: LabelModel?) {
        self.headline = headline
        self.body = body
        super.init()
    }
    
    //--------------------------------------------------
    // MARK: - Method
    //--------------------------------------------------
    
    override public func setDefaults() {
        style = .tallDivider
        super.setDefaults()
    }
    
    //--------------------------------------------------
    // MARK: - Keys
    //--------------------------------------------------
    
    private enum CodingKeys: String, CodingKey {
        case moleculeName
        case headline
        case body
    }
    
    //--------------------------------------------------
    // MARK: - Codec
    //--------------------------------------------------
    
    required public init(from decoder: Decoder) throws {
        let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
        headline = try typeContainer.decode(LabelModel.self, forKey: .headline)
        body = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .body)
        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(moleculeName, forKey: .moleculeName)
        try container.encode(headline, forKey: .headline)
        try container.encodeIfPresent(body, forKey: .body)
    }
}
