//
//  ListLeftVariableIconWithRightCaretModel.swift
//  MVMCoreUI
//
//  Created by Kruthika KP on 03/02/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//


public class ListLeftVariableIconWithRightCaretModel: ListItemModel, ParentMoleculeModelProtocol {
    //-----------------------------------------------------
    // MARK: - Properties
    //-----------------------------------------------------
    
    public static var identifier: String = "listLVImg"
    public var image: ImageViewModel
    public var leftLabel: LabelModel
    public var rightLabel: LabelModel
    
    public var children: [MoleculeModelProtocol] {
        return [image, leftLabel, rightLabel]
    }
    
    //-----------------------------------------------------
    // MARK: - Methods
    //-----------------------------------------------------
    
    override public func setDefaults() {
        super.setDefaults()
        if image.height == nil {
            image.height = 30.0
        }
        rightLabel.hero = 0
    }
    
    //-----------------------------------------------------
    // MARK: - Initializer
    //-----------------------------------------------------
    
    public init(image: ImageViewModel, leftLabel: LabelModel, rightLabel: LabelModel) {
        self.image = image
        self.leftLabel = leftLabel
        self.rightLabel = rightLabel
        super.init()
    }
    
    //-----------------------------------------------------
    // MARK: - Keys
    //-----------------------------------------------------
    
    private enum CodingKeys: String, CodingKey {
        case moleculeName
        case leftLabel
        case rightLabel
        case image
    }
    
    //-----------------------------------------------------
    // MARK: - Codec
    //-----------------------------------------------------
    
    required public init(from decoder: Decoder) throws {
        let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
        leftLabel = try typeContainer.decodeMolecule(codingKey: .leftLabel)
        rightLabel = try typeContainer.decodeMolecule(codingKey: .rightLabel)
        image = try typeContainer.decodeMolecule(codingKey: .image)
        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(leftLabel, forKey: .leftLabel)
        try container.encode(rightLabel, forKey: .rightLabel)
        try container.encode(image, forKey: .image)
    }
}
