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


public class ListTwoColumnPriceDescriptionModel: ListItemModel, MoleculeModelProtocol {
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    
    public static var identifier: String = "list2CTxtPrc1"
    public var leftHeadline: LabelModel
    public var leftBody: LabelModel
    public var rightLabel: LabelModel
    public var rightSubLabel: LabelModel
    
    //--------------------------------------------------
    // MARK: - Methods
    //--------------------------------------------------
    
    override public func setDefaults() {
        super.setDefaults()
        
        rightLabel.hero = 0
        
        if rightSubLabel.textColor == nil {
            rightSubLabel.textColor = Color(uiColor: .mvmCoolGray6)
        }
        
        if rightSubLabel.attributes == nil {
            rightSubLabel.attributes = [LabelAttributeStrikeThroughModel(0, rightSubLabel.text.count)]
        }
        
        if rightLabel.numberOfLines == nil {
            rightLabel.numberOfLines = 1
        }
        
        if rightSubLabel.numberOfLines == nil {
            rightSubLabel.numberOfLines = 1
        }
        
        if leftHeadline.numberOfLines == nil {
            leftHeadline.numberOfLines = 1
        }
    }
    
    //--------------------------------------------------
    // MARK: - Initializer
    //--------------------------------------------------
    
    public init(leftHeadline: LabelModel,leftBody: LabelModel, rightLabel: LabelModel, rightSubLabel: LabelModel) {
        self.leftHeadline = leftHeadline
        self.leftBody = leftBody
        self.rightLabel = rightLabel
        self.rightSubLabel = rightSubLabel
        super.init()
    }
    
    //--------------------------------------------------
    // MARK: - Keys
    //--------------------------------------------------
    
    private enum CodingKeys: String, CodingKey {
        case moleculeName
        case leftHeadline
        case leftBody
        case rightLabel
        case rightSubLabel
    }
    
    //--------------------------------------------------
    // MARK: - Codec
    //--------------------------------------------------
    
    required public init(from decoder: Decoder) throws {
        let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
        leftHeadline = try typeContainer.decode(LabelModel.self, forKey: .leftHeadline)
        leftBody = try typeContainer.decode(LabelModel.self, forKey: .leftBody)
        rightLabel = try typeContainer.decode(LabelModel.self, forKey: .rightLabel)
        rightSubLabel = try typeContainer.decode(LabelModel.self, forKey: .rightSubLabel)
        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(leftHeadline, forKey: .leftHeadline)
        try container.encode(leftBody, forKey: .leftBody)
        try container.encode(rightLabel, forKey: .rightLabel)
        try container.encode(rightSubLabel, forKey: .rightSubLabel)
    }
}
