 //
 
 import Foundation
+import WatchConnectivity
+import CoreData
+
+#if os(iOS)
+    public typealias WindManagerResult = UIBackgroundFetchResult
+    #else
+    public typealias WindManagerResult = Void
+#endif
+
 
 @objc(WindManager)
 public class WindManager : NSObject {


        if remainingStations <= 0 {
            isUpdating = false
            completionHandler?(.NoData)
            return
        }

        for station in stations {
            let complete = { (success:Bool, plots: [AnyObject]!) -> Void in
                CDPlot.updatePlots(plots ?? [CDPlot](), completion: { () -> Void in
                    remainingStations -= 1

                    if remainingStations == 0 {
                        DLOG("Finished")

                        self.isUpdating = false
                        completionHandler?(.NewData)
                    }
                })
            }

            let error = { (cancelled:Bool, error: NSError!) -> Void in
                DLOG("error: \(error)")
            }

            RHEVindsidenAPIClient.defaultManager().fetchStationsPlotsForStation(station.stationId, completion: complete, error: error)
        }
    }


    public func fetchForStationId( stationId: Int, completionHandler: ((UIBackgroundFetchResult) -> Void)? = nil ) -> Void {
        RHEVindsidenAPIClient.defaultManager().fetchStationsPlotsForStation(stationId, completion: { (success:Bool, plots: [AnyObject]!) -> Void in
            CDPlot.updatePlots(plots, completion: { () -> Void in
                completionHandler?(.NewData)
            })
            }, error: { (cancelled: Bool, error: NSError!) -> Void in
                completionHandler?(.NewData)
        })
    }



    func applicationDidEnterBackground( application: UIApplication) -> Void {
        stopUpdating()
    }
    #endif
}

