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

import Foundation


public class ListProgressBarDataModel: ListItemModel, MoleculeModelProtocol {
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    
    public static var identifier: String = "listPrgBarData"
    public var progressBar : MultiProgressBarModel
    public var leftLabel: LabelModel
    public var rightLabel: LabelModel
  
    //--------------------------------------------------
    // MARK: - Initializer
    //--------------------------------------------------
    
    public init (progressBar: MultiProgressBarModel, leftLabel: LabelModel, rightLabel: LabelModel){
        self.progressBar = progressBar
        self.leftLabel = leftLabel
        self.rightLabel = rightLabel
        super.init()
    }
    
    //--------------------------------------------------
    // MARK: - Keys
    //--------------------------------------------------
    
    private enum CodingKeys: String, CodingKey{
        case moleculeName
        case progressBar
        case leftLabel
        case rightLabel
    }
    
    //--------------------------------------------------
    // MARK: - Codec
    //--------------------------------------------------
    
    required public init(from decoder: Decoder) throws {
        let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
        progressBar = try typeContainer.decode(MultiProgressBarModel.self, forKey: .progressBar)
        leftLabel = try typeContainer.decode(LabelModel.self, forKey: .leftLabel)
        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(progressBar, forKey: .progressBar)
        try container.encode(leftLabel, forKey: .leftLabel)
        try container.encode(rightLabel, forKey: .rightLabel)
    }
}
