//
//  HeadersH2ButtonsModel.swift
//  MVMCoreUI
//
//  Created by Lekshmi S on 10/03/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//

import Foundation


public class HeadersH2ButtonsModel: HeaderModel, MoleculeModelProtocol {
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    
    public static var identifier: String = "headerH2Btns"
    public var headlineBody: HeadlineBodyModel
    public var buttons: TwoButtonViewModel
    
    //--------------------------------------------------
    // MARK: - Initializer
    //--------------------------------------------------
    
    public init(headlineBody: HeadlineBodyModel, buttons: TwoButtonViewModel) {
        self.headlineBody = headlineBody
        self.buttons = buttons
        super.init()
    }
    
    //--------------------------------------------------
    // MARK: - Methods
    //--------------------------------------------------
    
    public override func setDefaults() {
        if topPadding == nil {
            topPadding = Padding.Component.VerticalMarginSpacing
        }
        if bottomPadding == nil {
            bottomPadding = Padding.Component.VerticalMarginSpacing
        }
        super.setDefaults()
    }
    
    //--------------------------------------------------
    // MARK: - Keys
    //--------------------------------------------------
    
    private enum CodingKeys: String, CodingKey {
        case moleculeName
        case headlineBody
        case buttons
    }
    
    //--------------------------------------------------
    // MARK: - Codec
    //--------------------------------------------------
    
    required public init(from decoder: Decoder) throws {
        let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
        headlineBody = try typeContainer.decode(HeadlineBodyModel.self, forKey: .headlineBody)
        buttons = try typeContainer.decode(TwoButtonViewModel.self, forKey: .buttons)
        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(headlineBody, forKey: .headlineBody)
        try container.encode(buttons, forKey: .buttons)
    }
}
