//
//  TagsModel.swift
//  MVMCoreUI
//
//  Created by Dhamodaram Nandi on 27/05/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//

import Foundation

@objcMembers public class TagsModel: MoleculeModelProtocol {
    public static var identifier: String = "tags"
    public var backgroundColor: Color?
    public var tags: [TagModel]
    
    private enum CodingKeys: String, CodingKey {
        case moleculeName
        case backgroundColor
        case tags
    }
    
    required public init(from decoder: Decoder) throws {
        let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
        tags = try typeContainer.decode([TagModel].self, forKey: .tags)
        backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
    }
    
    public func encode(to encoder: Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(moleculeName, forKey: .moleculeName)
        try container.encode(tags, forKey: .tags)
        try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
    }
}
