//
//  NotificationXButtonModel.swift
//  MVMCoreUI
//
//  Created by Scott Pfeil on 9/15/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//

import Foundation

public class NotificationXButtonModel: ButtonModelProtocol, MoleculeModelProtocol {
    public static var identifier: String = "notificationXButton"
    public var backgroundColor: Color?
    public var color: Color?
    public var action: ActionModelProtocol = ActionNoopModel()
    
    private enum CodingKeys: String, CodingKey {
        case moleculeName
        case color
        case action
    }
    
    public init() {}
    
    public required init(from decoder: Decoder) throws {
        let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
        color = try typeContainer.decodeIfPresent(Color.self, forKey: .color)
        if let action: ActionModelProtocol = try typeContainer.decodeModelIfPresent(codingKey: .action) {
            self.action = action
        }
    }
    
    public func encode(to encoder: Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(moleculeName, forKey: .moleculeName)
        try container.encodeIfPresent(color, forKey: .color)
        try container.encodeModel(action, forKey: .action)
    }
}
