//
//  BaseDropdownEntryFieldModel.swift
//  MVMCoreUI
//
//  Created by Kevin Christiano on 1/22/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//

@objcMembers open class BaseDropdownEntryFieldModel: TextEntryFieldModel {
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    
    public var caretView: CaretViewModel?
    public var action: ActionModelProtocol?
    
    public override class var identifier: String { "" }
    
    //--------------------------------------------------
    // MARK: - Keys
    //--------------------------------------------------
    
    private enum CodingKeys: String, CodingKey {
        case moleculeName
        case caretView
        case action
    }
    
    //--------------------------------------------------
    // MARK: - Codec
    //--------------------------------------------------
    
    required public init(from decoder: Decoder) throws {
        try super.init(from: decoder)
        let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
        caretView = try typeContainer.decodeIfPresent(CaretViewModel.self, forKey: .caretView)
        action = try typeContainer.decodeModelIfPresent(codingKey: .action)
    }
    
    public override func encode(to encoder: Encoder) throws {
        try super.encode(to: encoder)
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(moleculeName, forKey: .moleculeName)
        try container.encode(caretView, forKey: .caretView)
        try container.encodeModelIfPresent(action, forKey: .action)
    }
}
