//
//  DashLineModel.swift
//  MVMCoreUI
//
//  Created by Ryan on 11/20/19.
//  Copyright © 2019 Verizon Wireless. All rights reserved.
//

import Foundation


@objcMembers public class DashLineModel: MoleculeModelProtocol {
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    
    public static var identifier: String = "dashLine"
    public var backgroundColor: Color?
    public var accessibilityIdentifier: String?
    public var dashColor: Color = Color(uiColor: .mvmCoolGray3)
    public var dashColor_inverted: Color = Color(uiColor: .mvmWhite)
    public var isHidden: Bool = false
    public var inverted: Bool = false
    
    //--------------------------------------------------
    // MARK: - Initializer
    //--------------------------------------------------
    
    public init(dashColor: Color) {
        self.dashColor = dashColor
    }
    
    //--------------------------------------------------
    // MARK: - Keys
    //--------------------------------------------------
    
    private enum CodingKeys: String, CodingKey {
        case moleculeName
        case backgroundColor
        case accessibilityIdentifier
        case dashColor_inverted
        case dashColor
        case isHidden
    }
   
    //--------------------------------------------------
    // MARK: - codec
    //--------------------------------------------------
    
    required public init(from decoder: Decoder) throws {
        let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
        
        if let dashColor = try typeContainer.decodeIfPresent(Color.self, forKey: .dashColor) {
            self.dashColor = dashColor
        }
        
        if let dashColor_inverted = try typeContainer.decodeIfPresent(Color.self, forKey: .dashColor_inverted) {
            self.dashColor_inverted = dashColor_inverted
        }
        
        backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
        accessibilityIdentifier = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityIdentifier)
        
        if let isHidden = try typeContainer.decodeIfPresent(Bool.self, forKey: .isHidden) {
            self.isHidden = isHidden
        }
    }
    
    public func encode(to encoder: Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(moleculeName, forKey: .moleculeName)
        try container.encode(dashColor, forKey: .dashColor)
        try container.encode(isHidden, forKey: .isHidden)
        try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
        try container.encodeIfPresent(accessibilityIdentifier, forKey: .accessibilityIdentifier)
    }
}
