//
//  ListOneColumnFullWidthTextAllTextAndLinksModel.swift
//  MVMCoreUI
//
//  Created by Kruthika KP on 14/02/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//

import Foundation


public class ListOneColumnFullWidthTextAllTextAndLinksModel: ListItemModel, MoleculeModelProtocol {
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    
    public static var identifier: String = "list1CTxt"
    public var eyebrow: LabelModel?
    public var headline : LabelModel?
    public var subHeadline: LabelModel?
    public var body: LabelModel?
    public var link : LinkModel?
    
    //--------------------------------------------------
    // MARK: - Initializer
    //--------------------------------------------------
    
    public init(eyebrow: LabelModel? = nil, headline: LabelModel? = nil, subHeadline: LabelModel? = nil, body: LabelModel? = nil, link: LinkModel? = nil) {
        self.eyebrow = eyebrow
        self.headline = headline
        self.subHeadline = subHeadline
        self.body = body
        self.link = link
        super.init()
    }
    
    //--------------------------------------------------
    // MARK: - Keys
    //--------------------------------------------------
    
    private enum CodingKeys: String, CodingKey {
        case moleculeName
        case eyebrow
        case headline
        case subHeadline
        case body
        case link
    }
    
    //--------------------------------------------------
    // 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)
        subHeadline = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .subHeadline)
        body = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .body)
        link = try typeContainer.decodeIfPresent(LinkModel.self, forKey: .link)
        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.encodeIfPresent(moleculeName, forKey: .moleculeName)
        try container.encodeIfPresent(eyebrow, forKey: .eyebrow)
        try container.encodeIfPresent(headline, forKey: .headline)
        try container.encodeIfPresent(subHeadline, forKey: .subHeadline)
        try container.encodeIfPresent(body, forKey: .body)
        try container.encodeIfPresent(link, forKey: .link)
    }
}
