<commit_before>// Copyright (c) 2015-2019 <NAME>
// 
// See the file LICENSE for copying permission.

import Foundation

public typealias UserInfo = [AnyHashable : Any]

extension Licensing {
    
    public func userInfo() -> UserInfo {
        
        switch self {
        case let .trial(trialPeriod):
            return [
                "registered" : false,
                "on_trial" : true,
                "trial_start_date"  : trialPeriod.startDate,
                "trial_end_date" : trialPeriod.endDate,
            ]
        case let .registered(license):
            return [
                "registered" : true,
                "on_trial" : false,
                "name" : license.name,
                "licenseCode"  : license.licenseCode
            ]
        case .trialUp:
            return [
                "registered" : false,
                "on_trial" : false
            ]
        }
    }
    
    public static func fromUserInfo(userInfo: UserInfo) -> Licensing? {
        
        guard let registered = userInfo["registered"] as? Bool else {
            return nil
        }
        
        if let onTrial = userInfo["on_trial"] as? Bool,
            !registered {
            
            guard onTrial else { return .trialUp }
            
            if let startDate = userInfo["trial_start_date"] as? Date,
                let endDate = userInfo["trial_end_date"] as? Date {
                    
                return .trial(TrialPeriod(startDate: startDate, endDate: endDate))
            }
        }
        
        guard let name = userInfo["name"] as? String,
            let licenseCode = userInfo["licenseCode"] as? String
            else { return nil }
        
        return .registered(License(name: name, licenseCode: licenseCode))
    }
}


extension Licensing {
    public static let licenseChangedNotification: Notification.Name = Notification.Name(rawValue: "License Changed")
}

public class LicenseChangeBroadcaster {
    let notificationCenter: NotificationCenter

    public init(notificationCenter: NotificationCenter) {
        self.notificationCenter = notificationCenter
    }

    public func broadcast(_ licensing: Licensing) {
        notificationCenter.post(
            name: Licensing.licenseChangedNotification,
            object: self,
            userInfo: licensing.userInfo())<commit_msg>fix default value for LicenseChangeBroadcaster parameter<commit_after>// Copyright (c) 2015-2019 <NAME>
// 
// See the file LICENSE for copying permission.

import Foundation

public typealias UserInfo = [AnyHashable : Any]

extension Licensing {
    
    public func userInfo() -> UserInfo {
        
        switch self {
        case let .trial(trialPeriod):
            return [
                "registered" : false,
                "on_trial" : true,
                "trial_start_date"  : trialPeriod.startDate,
                "trial_end_date" : trialPeriod.endDate,
            ]
        case let .registered(license):
            return [
                "registered" : true,
                "on_trial" : false,
                "name" : license.name,
                "licenseCode"  : license.licenseCode
            ]
        case .trialUp:
            return [
                "registered" : false,
                "on_trial" : false
            ]
        }
    }
    
    public static func fromUserInfo(userInfo: UserInfo) -> Licensing? {
        
        guard let registered = userInfo["registered"] as? Bool else {
            return nil
        }
        
        if let onTrial = userInfo["on_trial"] as? Bool,
            !registered {
            
            guard onTrial else { return .trialUp }
            
            if let startDate = userInfo["trial_start_date"] as? Date,
                let endDate = userInfo["trial_end_date"] as? Date {
                    
                return .trial(TrialPeriod(startDate: startDate, endDate: endDate))
            }
        }
        
        guard let name = userInfo["name"] as? String,
            let licenseCode = userInfo["licenseCode"] as? String
            else { return nil }
        
        return .registered(License(name: name, licenseCode: licenseCode))
    }
}


extension Licensing {
    public static let licenseChangedNotification: Notification.Name = Notification.Name(rawValue: "License Changed")
}

public class LicenseChangeBroadcaster {
    let notificationCenter: NotificationCenter

    public init(notificationCenter: NotificationCenter = .default) {
        self.notificationCenter = notificationCenter
    }

    public func broadcast(_ licensing: Licensing) {
        notificationCenter.post(
            name: Licensing.licenseChangedNotification,
            object: self,
            userInfo: licensing.userInfo())
{'fraction_non_alphanumeric': 0.08322877457130907, 'fraction_numerical': 0.003345880384776244, 'mean_word_length': 1.7378362907842015, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '3402709', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1167, 'n_words': 311}