//
//  ListThreeColumnBillChangesModel.swift
//  MVMCoreUI
//
//  Created by Subhankar Acharya on 22/07/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//


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