//
//  TwoLinkViewModel.swift
//  MVMCoreUI
//
//  Created by Scott Pfeil on 4/29/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//

import Foundation

public class TwoLinkViewModel: MoleculeModelProtocol {
    public static var identifier: String = "twoLinkView"
    public var backgroundColor: Color?
    public var rightLink: LinkModel?
    public var leftLink: LinkModel?
    
    private enum CodingKeys: String, CodingKey {
        case moleculeName
        case backgroundColor
        case rightLink
        case leftLink
    }

    public init(_ rightLink: LinkModel?, _ leftLink: LinkModel?) {
        self.rightLink = rightLink
        self.leftLink = leftLink
    }
    
    required public init(from decoder: Decoder) throws {
        let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
        backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
        rightLink = try typeContainer.decodeIfPresent(LinkModel.self, forKey: .rightLink)
        leftLink = try typeContainer.decodeIfPresent(LinkModel.self, forKey: .leftLink)
    }

    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.encodeIfPresent(rightLink, forKey: .rightLink)
        try container.encodeIfPresent(leftLink, forKey: .leftLink)
    }
}
