//
//  ListLeftVariableIconWithRightCaretAllTextLinksModel.swift
//  MVMCoreUI
//
//  Created by Dhamodaram Nandi on 26/10/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//

public class ListLeftVariableIconWithRightCaretAllTextLinksModel: ListItemModel, ParentMoleculeModelProtocol {
    
    //-----------------------------------------------------
    // MARK: - Properties
    //-----------------------------------------------------
    
    public static var identifier: String = "listLVImgRCAll"
    public var image: ImageViewModel
    public var eyebrowHeadlineBodyLink: EyebrowHeadlineBodyLinkModel
    public var rightLabel: LabelModel
    
    public var children: [MoleculeModelProtocol] {
        return [image, eyebrowHeadlineBodyLink, rightLabel]
    }
    
    //-----------------------------------------------------
    // MARK: - Methods
    //-----------------------------------------------------
    
    override public func setDefaults() {
        super.setDefaults()
        if image.width == nil, image.height == nil {
            image.width = 30
            image.height = 30
        }
        
        if rightLabel.numberOfLines == nil {
            rightLabel.numberOfLines = 1
        }
    }
    
    //-----------------------------------------------------
    // MARK: - Initializers
    //-----------------------------------------------------
    
    public init(image: ImageViewModel, eyebrowHeadlineBodyLink: EyebrowHeadlineBodyLinkModel, rightLabel: LabelModel) {
        self.image = image
        self.eyebrowHeadlineBodyLink = eyebrowHeadlineBodyLink
        self.rightLabel = rightLabel
        super.init()
    }
    
    //-----------------------------------------------------
    // MARK: - Keys
    //-----------------------------------------------------
    
    private enum CodingKeys: String, CodingKey {
        case moleculeName
        case image
        case eyebrowHeadlineBodyLink
        case rightLabel
    }
    
    //-----------------------------------------------------
    // MARK: - Codec
    //-----------------------------------------------------
    
    required public init(from decoder: Decoder) throws {
        let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
        image = try typeContainer.decode(ImageViewModel.self, forKey: .image)
        eyebrowHeadlineBodyLink = try typeContainer.decode(EyebrowHeadlineBodyLinkModel.self, forKey: .eyebrowHeadlineBodyLink)
        rightLabel = try typeContainer.decode(LabelModel.self, forKey: .rightLabel)
        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(image, forKey: .image)
        try container.encode(eyebrowHeadlineBodyLink, forKey: .eyebrowHeadlineBodyLink)
        try container.encode(rightLabel, forKey: .rightLabel)
    }
}
