//
//  LockUpsPlanNamesModel.swift
//  MVMCoreUI
//
//  Created by Lekshmi S on 15/07/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//

import Foundation
public class LockUpsPlanNamesModel: MoleculeModelProtocol {
    
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    public static var identifier: String = "planNamesLockup"
    public var backgroundColor: Color?
    public var headline: LabelModel
    public var subHeadline: LabelModel
    public var body: LabelModel
    
    //--------------------------------------------------
    // MARK: - Initializer
    //--------------------------------------------------
    public init(headline: LabelModel, subHeadline: LabelModel, body: LabelModel) {
        self.headline = headline
        self.subHeadline = subHeadline
        self.body = body
    }
    
    //--------------------------------------------------
    // MARK: - Keys
    //--------------------------------------------------
    private enum CodingKeys: String, CodingKey {
        case moleculeName
        case backgroundColor
        case headline
        case subHeadline
        case body
    }
    
    //--------------------------------------------------
    // MARK: - Codec
    //--------------------------------------------------
    required public init(from decoder: Decoder) throws {
        let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
        backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
        headline = try typeContainer.decode(LabelModel.self, forKey: .headline)
        subHeadline = try typeContainer.decode(LabelModel.self, forKey: .subHeadline)
        body = try typeContainer.decode(LabelModel.self, forKey: .body)
    }
    
    public func encode(to encoder: Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(moleculeName, forKey: .moleculeName)
        try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
        try container.encode(headline, forKey: .headline)
        try container.encode(subHeadline, forKey: .subHeadline)
        try container.encode(body, forKey: .body)
    }
}
