//
//  ThreeColumnPlanDataDividerListModel.swift
//  MVMCoreUI
//
//  Created by Acharya, Subhankar on 04/02/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//

import UIKit


public class ListThreeColumnPlanDataDividerModel: ListItemModel, MoleculeModelProtocol {
    //-----------------------------------------------------
    // MARK: - Properties
    //-----------------------------------------------------
    
    public static var identifier: String = "list3CHBDiv"
    public var leftHeadlineBody: HeadlineBodyModel
    public var centerHeadlineBody: HeadlineBodyModel
    public var rightHeadlineBody: HeadlineBodyModel
    
    //-----------------------------------------------------
    // MARK: - Initializer
    //-----------------------------------------------------
    
    public init(leftHeadlineBody: HeadlineBodyModel, centerHeadlineBody:HeadlineBodyModel, rightHeadlineBody: HeadlineBodyModel) {
        self.leftHeadlineBody = leftHeadlineBody
        self.centerHeadlineBody = centerHeadlineBody
        self.rightHeadlineBody = rightHeadlineBody
        super.init()
    }
    
    //-----------------------------------------------------
    // MARK: - Method
    //-----------------------------------------------------
    
    override public func setDefaults() {
        style = .tallDivider
        super.setDefaults()
        leftHeadlineBody.style = .itemHeader
        centerHeadlineBody.style = .itemHeader
        rightHeadlineBody.style = .itemHeader
    }
    
    //-----------------------------------------------------
    // MARK: - Keys
    //-----------------------------------------------------
    
    private enum CodingKeys: String, CodingKey {
        case moleculeName
        case leftHeadlineBody
        case centerHeadlineBody
        case rightHeadlineBody
    }
    
    //-----------------------------------------------------
    // MARK: - Codec
    //-----------------------------------------------------
    
    required public init(from decoder: Decoder) throws {
        let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
        leftHeadlineBody = try typeContainer.decode(HeadlineBodyModel.self, forKey: .leftHeadlineBody)
        centerHeadlineBody = try typeContainer.decode(HeadlineBodyModel.self, forKey: .centerHeadlineBody)
        rightHeadlineBody = try typeContainer.decode(HeadlineBodyModel.self, forKey: .rightHeadlineBody)
        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(leftHeadlineBody, forKey: .leftHeadlineBody)
        try container.encode(centerHeadlineBody, forKey: .centerHeadlineBody)
        try container.encode(rightHeadlineBody, forKey: .rightHeadlineBody)
    }
}

