//
//  ListLeftVariableCheckboxBodyTextModel.swift
//  MVMCoreUI
//
//  Created by Lekshmi S on 14/04/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//


open class ListLeftVariableCheckboxBodyTextModel: ListItemModel, MoleculeModelProtocol {
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    
    public static var identifier: String = "listLVCBBdy"
    public var checkbox: CheckboxModel
    public var headlineBody: HeadlineBodyModel
    
    //--------------------------------------------------
    // MARK: - Initializer
    //--------------------------------------------------
    
    public init(checkbox: CheckboxModel, headlineBody: HeadlineBodyModel) {
        self.checkbox = checkbox
        self.headlineBody = headlineBody
        super.init()
    }
    
    open override func setDefaults() {
        super.setDefaults()
        headlineBody.style = .item
        if let headline = headlineBody.headline {
            headline.hero = 0
        }
    }
    
    //--------------------------------------------------
    // MARK: - Keys
    //--------------------------------------------------
    
    private enum CodingKeys: String, CodingKey {
        case moleculeName
        case headlineBody
        case checkbox
    }
    
    //--------------------------------------------------
    // MARK: - Codec
    //--------------------------------------------------
    
    required public init(from decoder: Decoder) throws {
        let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
        headlineBody = try typeContainer.decode(HeadlineBodyModel.self, forKey: .headlineBody)
        checkbox = try typeContainer.decode(CheckboxModel.self, forKey: .checkbox)
        try super.init(from: decoder)
    }
    
    open 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(headlineBody, forKey: .headlineBody)
        try container.encode(checkbox, forKey: .checkbox)
    }
}
