//
//  JSONCreatorActionHandler.swift
//  JSONCreator
//
//  Created by Scott Pfeil on 1/25/21.
//  Copyright © 2021 Verizon Wireless. All rights reserved.
//

import Foundation
import MVMCoreUI

@objcMembers public class ActionPrintModel: ActionModelProtocol {
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    public static var identifier: String = "print"
    public var actionType: String = ActionPrintModel.identifier
    public var text: String = ""
    public var delay = false
    public var extraParameters: JSONValueDictionary?
    public var analyticsData: JSONValueDictionary?
}

public class JSONCreatorActionHandler: MVMCoreUIActionHandler {
    public override func handleOtherActions(_ actionType: String?, actionInformation: [AnyHashable : Any]?, additionalData: [AnyHashable : Any]?, delegateObject: DelegateObject?) -> Bool {
        if actionType == "print" {
            if actionInformation?.boolForKey("delay") ?? false {
                sleep(2)
            }
            print(actionInformation?.stringForkey("text") ?? "fail")
            return true
        }
        return super.handleOtherActions(actionType, actionInformation: actionInformation, additionalData: additionalData, delegateObject: delegateObject)
    }
    
    public static func doStuff() {
        MVMCoreObject.sharedInstance()?.actionHandler = JSONCreatorActionHandler()
        ModelRegistry.register(ActionPrintModel.self)
        ModelRegistry.register(handler: ButtonWithImage.self, for: ButtonWithImageModel.self)
        ModelRegistry.register(handler: OrderTracker.self, for: OrderTrackerModel.self)
        ModelRegistry.register(handler: ListDeviceRightVariableCaret.self, for: ListDeviceRightVariableCaretModel.self)
        ModelRegistry.register(handler: Links.self, for: LinksModel.self)
        try? ModelRegistry.throwable_register(handler: neView.self, model: neViewModl.self)
        if let bundle = MVMCoreUIUtility.bundleForMVMCoreUI() {
            MVMCoreCache.shared()?.registerBundle(forImages: bundle)
        }
    }
}
