<commit_before>//
//  Scenario.swift
//  Scenario
//
//  Created by <NAME> on 28.05.16.
//  Copyright © 2016 diniska. All rights reserved.
//

import Foundation

public typealias ScenarioParameters = [String: AnyObject!]
public typealias ScenarioResults = [String: AnyObject!]
public typealias ScenarioResulCallback = (result: ScenarioResults) -> ()

public protocol Scenario {
    func perfrom(from viewController: UIViewController, with parameters: ScenarioParameters?, callback: ScenarioResulCallback?)
}

public struct ScenarioStartedFromModalViewController: Scenario {
    public var createInitialViewController: (parameters: ScenarioParameters?, callback: ScenarioResulCallback) -> UIViewController?

    public func perfrom(from viewController: UIViewController, with parameters: ScenarioParameters?, callback: ScenarioResulCallback?) {
        let dismissCallback: ScenarioResulCallback = {[weak viewController] (result) in
            viewController?.dismissViewControllerAnimated(true) {
                callback?(result: result)
            }
        }
        guard let initialViewController = createInitialViewController(parameters: parameters, callback: dismissCallback)
            else { debugPrint("there is no possible view controller for such parameters"); return }
        viewController.presentViewController(initialViewController, animated: true, completion: nil)
    }
}

public struct ScenarioStartedFromNavigationViewController: Scenario {
    public var createInitialViewController: (parameters: ScenarioParameters?, callback: ScenarioResulCallback) -> UIViewController?

    public func perfrom(from viewController: UIViewController, with parameters: ScenarioParameters?, callback: ScenarioResulCallback?) {
        let presentationBlock: (initialViewController: UIViewController) -> ()
        let dismissBlock: () -> ()

        if let navigationController = viewController as? UINavigationController {
            presentationBlock = { (initialViewController) in
                navigationController.pushViewController(initialViewController, animated: true)
            }
            dismissBlock = { [weak navigationController] in
                navigationController?.popViewControllerAnimated(true)
            }
        } else if let navigationController = viewController.navigationController {
            presentationBlock = { (initialViewController) in<commit_msg>swift objects support improved<commit_after>//
//  Scenario.swift
//  Scenario
//
//  Created by <NAME> on 28.05.16.
//  Copyright © 2016 diniska. All rights reserved.
//

import UIKit

public typealias ScenarioParameters = [String: Any]
public typealias ScenarioResults = [String: Any]
public typealias ScenarioResultCallback = (result: ScenarioResults) -> ()

public protocol Scenario {
    func perfrom(from viewController: UIViewController, with parameters: ScenarioParameters?, callback: ScenarioResultCallback?)
}

public struct ScenarioStartedFromModalViewController: Scenario {
    public var createInitialViewController: (parameters: ScenarioParameters?, callback: ScenarioResultCallback) -> UIViewController?

    public func perfrom(from viewController: UIViewController, with parameters: ScenarioParameters?, callback: ScenarioResultCallback?) {
        let dismissCallback: ScenarioResultCallback = {[weak viewController] (result) in
            viewController?.dismissViewControllerAnimated(true) {
                callback?(result: result)
            }
        }
        guard let initialViewController = createInitialViewController(parameters: parameters, callback: dismissCallback)
            else { debugPrint("there is no possible view controller for such parameters"); return }
        viewController.presentViewController(initialViewController, animated: true, completion: nil)
    }
}

public struct ScenarioStartedFromNavigationViewController: Scenario {
    public var createInitialViewController: (parameters: ScenarioParameters?, callback: ScenarioResulCallback) -> UIViewController?

    public func perfrom(from viewController: UIViewController, with parameters: ScenarioParameters?, callback: ScenarioResulCallback?) {
        let presentationBlock: (initialViewController: UIViewController) -> ()
        let dismissBlock: () -> ()

        if let navigationController = viewController as? UINavigationController {
            presentationBlock = { (initialViewController) in
                navigationController.pushViewController(initialViewController, animated: true)
            }
            dismissBlock = { [weak navigationController] in
                navigationController?.popViewControllerAnimated(true)
            }
        } else if let navigationController = viewController.navigationController {
            presentationBlock = { (initialViewController) in
{'fraction_non_alphanumeric': 0.07617065556711759, 'fraction_numerical': 0.004162330905306972, 'mean_word_length': 4.080338266384778, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5864501', 'n_tokens_mistral': 1117, 'n_tokens_neox': 1043, 'n_words': 306}