 import Foundation
 import CoreLocation
 
-internal protocol LocationManager {
+internal protocol LocationManager: NSObjectProtocol {
 
+    static func locationServicesEnabled() -> Bool
+    static func authorizationStatus() -> CLAuthorizationStatus
+
+    weak var delegate: CLLocationManagerDelegate? { get set }
 }
 
 extension CLLocationManager: LocationManager { }

    }

    func dependencyForOperation(operation: Operation) -> NSOperation? {
        return LocationPermissionOperation(usage: usage)
    }

    func evaluateForOperation(operation: Operation, completion: OperationConditionResult -> Void) {

    }
}





    enum Usage: Int { case WhenInUse = 1, Always }

    enum Error: ErrorType {
        case LocationServicesNotEnabled
        case AuthenticationStatusNotSufficient(CLAuthorizationStatus, Usage)
    }

    private class LocationPermissionOperation: Operation {
        let usage: Usage
        var manager: LocationManager

        init(usage: Usage, manager: LocationManager) {
            self.usage = usage
            self.manager = manager
            super.init()
            addCondition(AlertPresentation())
        }

        private override func execute() {
            let actual = manager.dynamicType.authorizationStatus()
            switch (actual, usage) {
            case (.NotDetermined, _), (.AuthorizedWhenInUse, .Always):
                dispatch_async(Queue.Main.queue, requestPermission)
            default:
                finish()
            }
        }

        private func requestPermission() {
            manager.delegate = self

            
        }
    }

