//
//  ListRVWheelModel.swift
//  MVMCoreUI
//
//  Created by Arora, Prateek on 03/02/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//


public class ListRVWheelModel: ListItemModel, MoleculeModelProtocol {
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    
    public static var identifier: String = "listRVWheel"
    public var leftLabel: LabelModel
    public var rightLabel: LabelModel
    public var wheel: WheelModel
    
    //--------------------------------------------------
    // MARK: - Initializer
    //--------------------------------------------------
    
    public init(leftLabel: LabelModel, rightLabel: LabelModel, wheel: WheelModel) {
        self.leftLabel = leftLabel
        self.rightLabel = rightLabel
        self.wheel = wheel
        super.init()
    }
    
    //--------------------------------------------------
    // MARK: - Method
    //--------------------------------------------------
    
    override public func setDefaults() {
        super.setDefaults()
        rightLabel.hero = 0
    }
    
    //--------------------------------------------------
    // MARK: - Keys
    //--------------------------------------------------
    
    private enum CodingKeys: String, CodingKey {
        case moleculeName
        case leftLabel
        case rightLabel
        case wheel
    }
    
    //--------------------------------------------------
    // 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)
        rightLabel = try typeContainer.decode(LabelModel.self, forKey: .rightLabel)
        wheel = try typeContainer.decodeIfPresent(WheelModel.self, forKey: .wheel) ?? WheelModel()
        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(rightLabel, forKey: .rightLabel)
        try container.encode(wheel, forKey: .wheel)
    }
}
