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

import Foundation

public class HeadersH1LandingPageHeaderModel: HeaderModel, MoleculeModelProtocol {
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    public static var identifier: String = "headerH1Landing"
    public var headline: LabelModel
    public var headline2: LabelModel
    public var subHeadline: LabelModel
    public var body: LabelModel
    public var link: LinkModel
    public var buttons: TwoButtonViewModel
    
    //--------------------------------------------------
    // MARK: - Initializer
    //--------------------------------------------------
    public init(headline: LabelModel, headline2: LabelModel, subHeadline: LabelModel, body: LabelModel, link: LinkModel, buttons: TwoButtonViewModel) {
        self.headline = headline
        self.headline2 = headline2
        self.subHeadline = subHeadline
        self.body = body
        self.link = link
        self.buttons = buttons
        super.init()
    }

    //--------------------------------------------------
    // MARK: - Keys
    //--------------------------------------------------
    private enum CodingKeys: String, CodingKey {
        case moleculeName
        case headline
        case headline2
        case subHeadline
        case body
        case link
        case buttons
    }
    
    //--------------------------------------------------
    // MARK: - Codec
    //--------------------------------------------------
    required public init(from decoder: Decoder) throws {
        let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
        headline = try typeContainer.decode(LabelModel.self, forKey: .headline)
        headline2 = try typeContainer.decode(LabelModel.self, forKey: .headline2)
        subHeadline = try typeContainer.decode(LabelModel.self, forKey: .subHeadline)
        body = try typeContainer.decode(LabelModel.self, forKey: .body)
        link = try typeContainer.decode(LinkModel.self, forKey: .link)
        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(headline, forKey: .headline)
        try container.encode(headline2, forKey: .headline2)
        try container.encode(subHeadline, forKey: .subHeadline)
        try container.encode(body, forKey: .body)
        try container.encode(link, forKey: .link)
        try container.encode(buttons, forKey: .buttons)
    }
}
