//
//  LinksModel.swift
//  MobileFirstFramework
//
//  Created by Lekshmi S on 15/12/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//

import MVMCoreUI

@objcMembers public class LinksModel: MoleculeModelProtocol {
    @DecodableDefault.UUIDString public var id: String    
    public static var identifier: String = "links"
    public var backgroundColor: Color?
    public var links: [LinkModel]
    
    private enum CodingKeys: String, CodingKey {
        case id
        case moleculeName
        case backgroundColor
        case links
    }
    
    required public init(from decoder: Decoder) throws {
        let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
        backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
        links = try typeContainer.decode([LinkModel].self, forKey: .links)
    }
    
    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(links, forKey: .links)
    }
}
