//
//  ListDeviceComplexButtonSmallModel.swift
//  MVMCoreUI
//
//  Created by Dhamodaram Nandi on 24/04/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//

import Foundation


public class ListDeviceComplexButtonSmallModel: ListItemModel, MoleculeModelProtocol {
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    
    public static var identifier: String = "listDvcBtnS"
    public var eyebrow: LabelModel?
    public var headline: LabelModel?
    public var body: LabelModel?
    public var body2: LabelModel?
    public var button: ButtonModel
    public var image: ImageViewModel
    
    //--------------------------------------------------
    // MARK: - Initializer
    //--------------------------------------------------
    
    public init(eyebrow: LabelModel, headline:LabelModel, body: LabelModel, body2: LabelModel, button: ButtonModel, image: ImageViewModel) {
        self.eyebrow = eyebrow
        self.headline = headline
        self.body = body
        self.body2 = body2
        self.button = button
        self.image = image
        super.init()
    }
    
    //--------------------------------------------------
    // MARK: - Methods
    //--------------------------------------------------
    
    override public func setDefaults() {
        super.setDefaults()
        button.size = .tiny
        button.style = .secondary
    }
    
    //--------------------------------------------------
    // MARK: - Keys
    //--------------------------------------------------
    
    private enum CodingKeys: String, CodingKey {
        case moleculeName
        case eyebrow
        case headline
        case body
        case body2
        case button
        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)
        button = try typeContainer.decode(ButtonModel.self, forKey: .button)
        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(button, forKey: .button)
        try container.encode(image, forKey: .image)
    }
}
