//
//  ListDeviceComplexLinkMediumModel.swift
//  MVMCoreUI
//
//  Created by Lekshmi S on 21/04/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//

import Foundation


public class ListDeviceComplexLinkMediumModel: ListItemModel, MoleculeModelProtocol {
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    
    public static var identifier: String = "listDvcLnkM"
    public var eyebrow: LabelModel?
    public var headline: LabelModel?
    public var body: LabelModel?
    public var body2: LabelModel?
    public var twoLinkView: TwoLinkViewModel
    public var image: ImageViewModel
    
    //--------------------------------------------------
    // MARK: - Initializer
    //--------------------------------------------------
    
    public init(eyebrow: LabelModel, headline: LabelModel, body: LabelModel, body2: LabelModel, twoLinkView: TwoLinkViewModel, image: ImageViewModel) {
        self.eyebrow = eyebrow
        self.headline = headline
        self.body = body
        self.body2 = body2
        self.twoLinkView = twoLinkView
        self.image = image
        super.init()
    }
    
    //--------------------------------------------------
    // MARK: - Keys
    //--------------------------------------------------
    
    private enum CodingKeys: String, CodingKey {
        case moleculeName
        case eyebrow
        case headline
        case body
        case body2
        case twoLinkView
        case image
    }
    
    //--------------------------------------------------
    // MARK: - Codec
    //--------------------------------------------------
    
    required public init(from decoder: Decoder) throws {
        let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
        eyebrow = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .eyebrow)
        headline = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .headline)
        body = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .body)
        body2 = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .body2)
        twoLinkView = try typeContainer.decode(TwoLinkViewModel.self, forKey: .twoLinkView)
        image = try typeContainer.decode(ImageViewModel.self, forKey: .image)
        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.encodeIfPresent(eyebrow, forKey: .eyebrow)
        try container.encodeIfPresent(headline, forKey: .headline)
        try container.encodeIfPresent(body, forKey: .body)
        try container.encodeIfPresent(body2, forKey: .body2)
        try container.encode(twoLinkView, forKey: .twoLinkView)
        try container.encode(image, forKey: .image)
    }
}
