//
//  ActionModelAdapter.swift
//  MVMCoreUI
//
//  Created by Kyle on 3/25/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//

public extension Dictionary {
    
    func asActionModel() throws -> ActionModelProtocol {
        guard let castedSelf = self as? [String: Any] else {
            throw ModelRegistry.Error.decoderOther(message: "Dictionary is not of type [String: Any]")
        }
        guard let actionType = ModelRegistry.getType(for: castedSelf.stringForkey(KeyActionType), with: ActionModelProtocol.self) else {
            throw ModelRegistry.Error.decoderErrorModelNotMapped()
        }
        guard let actionModel = try actionType.decode(jsonDict: castedSelf) as? ActionModelProtocol else {
            throw ModelRegistry.Error.decoderOther(message: "Could not decode to ActionModelProtocol")
        }
        return actionModel
    }
    
}
