//
//  ListRightVariableRightCaretAlltextAndLinksModel.swift
//  MVMCoreUI
//
//  Created by Lekshmi S on 23/07/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//


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