<commit_before>//
//  WatchDataManager.swift
//  StudyBox_iOS
//
//  Created by <NAME> on 15.04.2016.
//  Copyright © 2016 BLStream. All rights reserved.
//

import WatchConnectivity
import UIKit

//WatchDataManager is implemented because updating the Watch data will occur in Settings and later when user edits a deck or flashcard data.
class WatchDataManager: NSObject, WCSessionDelegate {
    
    static let watchManager = WatchDataManager()
    private var dataManager: DataManager? = { return UIApplication.appDelegate().dataManager }()
    private let session: WCSession? = WCSession.isSupported() ? WCSession.defaultSession() : nil
    
    private var validSession: WCSession? {
        if let session = session where session.paired && session.watchAppInstalled {
            return session
        }
        return nil
    }
    
    func startSession() {
        session?.delegate = self
        session?.activateSession()
    }
    
    //Sends an array with deck IDs to Apple Watch
    func sendDecksToAppleWatch(decksIDs: [String]) throws {
        
        var flashcardsQuestions = [String]()
        var flashcardsAnswers = [String]()
        var flashcardsIDs = [String]()
        var flashcardsTips = [String]()
        
        if let manager = dataManager {
            for deck in decksIDs {
                if let deckFromManager = manager.deck(withId: deck) {
                    for flashcard in deckFromManager.flashcards where !flashcard.hidden {
                        flashcardsQuestions.append(flashcard.question)
                        flashcardsAnswers.append(flashcard.answer)
                        flashcardsIDs.append(flashcard.serverID)
                        flashcardsTips.append(flashcard.tip)
                    }
                }
            }
        }
        
        if !flashcardsQuestions.isEmpty && !flashcardsAnswers.isEmpty {
            do {
                try self.updateApplicationContext([
                    Utils.WatchAppContextType.FlashcardsQuestions: flashcardsQuestions,
                    Utils.WatchAppContextType.FlashcardsAnswers: flashcardsAnswers,<commit_msg>fix error<commit_after>//
//  WatchDataManager.swift
//  StudyBox_iOS
//
//  Created by <NAME> on 15.04.2016.
//  Copyright © 2016 BLStream. All rights reserved.
//

import WatchConnectivity
import UIKit

//WatchDataManager is implemented because updating the Watch data will occur in Settings and later when user edits a deck or flashcard data.
class WatchDataManager: NSObject, WCSessionDelegate {
    
    static let watchManager = WatchDataManager()
    private var dataManager: DataManager? = { return UIApplication.appDelegate().dataManager }()
    private let session: WCSession? = WCSession.isSupported() ? WCSession.defaultSession() : nil
    
    private var validSession: WCSession? {
        if let session = session where session.paired && session.watchAppInstalled {
            return session
        }
        return nil
    }
    
    func startSession() {
        session?.delegate = self
        session?.activateSession()
    }
    
    //Sends an array with deck IDs to Apple Watch
    func sendDecksToAppleWatch(decksIDs: [String]) throws {
        
        var flashcardsQuestions = [String]()
        var flashcardsAnswers = [String]()
        var flashcardsIDs = [String]()
        var flashcardsTips = [String]()
        
        if let manager = dataManager {
            for deck in decksIDs {
                if let deckFromManager = manager.deck(withId: deck) {
                    for flashcard in deckFromManager.flashcards where !flashcard.hidden {
                        flashcardsQuestions.append(flashcard.question)
                        flashcardsAnswers.append(flashcard.answer)
                        flashcardsIDs.append(flashcard.serverID)
//                        flashcardsTips.append(flashcard.tip)
//TODO: fix handling tips
                    }
                }
            }
        }
        
        if !flashcardsQuestions.isEmpty && !flashcardsAnswers.isEmpty {
            do {
                try self.updateApplicationContext([
                    Utils.WatchAppContextType.FlashcardsQuestions: flashcardsQuestions,
                    Utils.WatchAppContextType.FlashcardsAnswers: flashcardsAnswers,
{'fraction_non_alphanumeric': 0.0752212389380531, 'fraction_numerical': 0.0055891942244993015, 'mean_word_length': 2.0988455988455987, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3085721', 'n_tokens_mistral': 1135, 'n_tokens_neox': 1052, 'n_words': 284}