//
//  NSUserActivity+Extensions.swift
//  Tusker
//
//  Created by Shadowfacts on 10/19/18.
//  Copyright © 2018 Shadowfacts. All rights reserved.
//

import Foundation

extension NSUserActivity {
    
    var displaysAuxiliaryScene: Bool {
        get {
            (userInfo?["displaysAuxiliaryScene"] as? Bool) ?? false
        }
        set {
            if userInfo == nil {
                userInfo = [:]
            }
            userInfo!["displaysAuxiliaryScene"] = newValue
        }
    }
    
    var isStateRestorationActivity: Bool {
        get {
            (userInfo?["isStateRestorationActivity"] as? Bool) ?? false
        }
        set {
            if userInfo == nil {
                userInfo = [:]
            }
            userInfo!["isStateRestorationActivity"] = newValue
        }
    }

    convenience init(type: UserActivityType, accountID: String) {
        self.init(activityType: type.rawValue)
        self.userInfo = [
            "accountID": accountID
        ]
    }
    
    @MainActor
    func handleResume(manager: UserActivityManager) -> Bool {
        guard let type = UserActivityType(rawValue: activityType) else { return false }
        type.handle(manager)(self)
        return true
    }
    
}
