//
//  ThreeHeadlineBodyLinkModel.swift
//  MVMCoreUI
//
//  Created by Kevin Christiano on 6/4/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//

import Foundation


public class ThreeHeadlineBodyLinkModel: MoleculeModelProtocol {
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    
    public static var identifier: String = "threeHeadlineBodyLink"
    public var moleculeName: String = ThreeHeadlineBodyLinkModel.identifier
    public var backgroundColor: Color?
    
    public var headline1: LabelModel
    public var headline2: LabelModel
    public var headline3: LabelModel
    public var body: LabelModel
    public var link: LinkModel
    
    //--------------------------------------------------
    // MARK: - Initializer
    //--------------------------------------------------
    
    public init(headline1: LabelModel, headline2: LabelModel, headline3: LabelModel, body: LabelModel, link: LinkModel) {
        self.headline1 = headline1
        self.headline2 = headline2
        self.headline3 = headline3
        self.body = body
        self.link = link
    }
    
    //--------------------------------------------------
    // MARK: - Keys
    //--------------------------------------------------
    
    private enum CodingKeys: String, CodingKey {
        case moleculeName
        case backgroundColor
        case headline1
        case headline2
        case headline3
        case body
        case link
    }
    
    //--------------------------------------------------
    // MARK: - Codec
    //--------------------------------------------------
    
    required public init(from decoder: Decoder) throws {
        let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
        backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
        headline1 = try typeContainer.decode(LabelModel.self, forKey: .headline1)
        headline2 = try typeContainer.decode(LabelModel.self, forKey: .headline2)
        headline3 = try typeContainer.decode(LabelModel.self, forKey: .headline3)
        body = try typeContainer.decode(LabelModel.self, forKey: .body)
        link = try typeContainer.decode(LinkModel.self, forKey: .link)
    }
    
    public func encode(to encoder: Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(moleculeName, forKey: .moleculeName)
        try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
        try container.encode(headline1, forKey: .headline1)
        try container.encode(headline2, forKey: .headline2)
        try container.encode(headline3, forKey: .headline3)
        try container.encode(body, forKey: .body)
        try container.encode(link, forKey: .link)
    }
}
