//
//  ListItem.swift
//  MVMCoreUI
//
//  Created by Suresh, Kamlesh on 10/3/19.
//  Copyright © 2019 Suresh, Kamlesh. All rights reserved.
//

import Foundation

@objcMembers public class ListItemModel: MoleculeContainerModel, MoleculeProtocol {
    public static var identifier: String = "listItem"
    public var backgroundColor: String?
    public var action: ActionModel?
    public var line: LineModel?

    enum ListItemCodingKeys: String, CodingKey {
        case moleculeName
        case action
        case line
    }

    required public init(from decoder: Decoder) throws {
        try super.init(from: decoder)
        let typeContainer = try decoder.container(keyedBy: ListItemCodingKeys.self)
        self.action = try typeContainer.decodeIfPresent(ActionModel.self, forKey: .action)
        line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line)
    }
    
    public override func encode(to encoder: Encoder) throws {
        try super.encode(to: encoder)
        var container = encoder.container(keyedBy: ListItemCodingKeys.self)
        try container.encode(moleculeName, forKey: .moleculeName)
        try container.encodeIfPresent(action, forKey: .action)
        try container.encodeIfPresent(line, forKey: .line)
    }    
}
