//
//  ListTwoColumnDropdownSelectorsModel.swift
//  MVMCoreUI
//
//  Created by Kruthika KP on 27/04/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//


public class ListTwoColumnDropdownSelectorsModel: ListItemModel, MoleculeModelProtocol {
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    
    public static var identifier: String = "list2CDrpDrp1"
    public var leftDropDown: ItemDropdownEntryFieldModel
    public var rightDropDown: ItemDropdownEntryFieldModel
    
    //--------------------------------------------------
    // MARK: - Method
    //--------------------------------------------------
    
    override public func setDefaults() {
        if useHorizontalMargins == nil {
            useHorizontalMargins = true
        }
        
        if useVerticalMargins == nil {
            useVerticalMargins = true
        }
        
        if topPadding == nil {
            topPadding = 20
        }
        
        if bottomPadding == nil {
            bottomPadding = 0
        }
        if line == nil {
            line = LineModel(type: .none)
        }
    }
    
    //--------------------------------------------------
    // MARK: - Initializer
    //--------------------------------------------------
    
    public init(leftDropDown: ItemDropdownEntryFieldModel, rightDropDown: ItemDropdownEntryFieldModel) {
        self.leftDropDown = leftDropDown
        self.rightDropDown = rightDropDown
        super.init()
    }
    
    //--------------------------------------------------
    // MARK: - Keys
    //--------------------------------------------------
    
    private enum CodingKeys: String, CodingKey {
        case moleculeName
        case leftDropDown
        case rightDropDown
    }
    
    //--------------------------------------------------
    // MARK: - Codec
    //--------------------------------------------------
    
    required public init(from decoder: Decoder) throws {
        let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
        leftDropDown = try typeContainer.decode(ItemDropdownEntryFieldModel.self, forKey: .leftDropDown)
        rightDropDown = try typeContainer.decode(ItemDropdownEntryFieldModel.self, forKey: .rightDropDown)
        try super.init(from: decoder)
    }
    
    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(leftDropDown, forKey: .leftDropDown)
        try container.encode(rightDropDown, forKey: .rightDropDown)
    }
}
