//
//  ListRightVariablePriceChangeBodyTextModel.swift
//  MVMCoreUI
//
//  Created by Dhamodaram Nandi on 13/04/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//


public class ListRightVariablePriceChangeBodyTextModel: ListItemModel, MoleculeModelProtocol {
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    
    public static var identifier: String = "listRVArwBdy"
    public var headlineBody: HeadlineBodyModel
    public var rightLabel: LabelModel
    public var arrow: ArrowModel
    
    //--------------------------------------------------
    // MARK: - Initializer
    //--------------------------------------------------
    
    public init(headlineBody: HeadlineBodyModel,rightLabel: LabelModel,arrow: ArrowModel) {
        self.headlineBody = headlineBody
        self.rightLabel = rightLabel
        self.arrow = arrow
        super.init()
    }
    
    //--------------------------------------------------
    // MARK: - Methods
    //--------------------------------------------------
    
    public override func setDefaults() {
        super.setDefaults()
        if let headline = headlineBody.headline {
            headline.hero = 0
        }
        if rightLabel.numberOfLines == nil {
            rightLabel.numberOfLines = 1
        }
    }
    
    //--------------------------------------------------
    // MARK: - Keys
    //--------------------------------------------------
    
    private enum CodingKeys: String, CodingKey {
        case moleculeName
        case headlineBody
        case rightLabel
        case arrow
    }
    
    //--------------------------------------------------
    // 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)
        rightLabel = try typeContainer.decode(LabelModel.self, forKey: .rightLabel)
        arrow = try typeContainer.decode(ArrowModel.self, forKey: .arrow)
        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(headlineBody, forKey: .headlineBody)
        try container.encode(rightLabel, forKey: .rightLabel)
        try container.encode(arrow, forKey: .arrow)
    }
}
