import Foundation
import os.log
import FirebaseAnalytics

protocol AnalyticsRepository {
    func sendScreenView(_ name: String, parameters: [String: String])
    func sendEvent(action: String, parameters: [String: String])
}

extension AnalyticsRepository {

    func sendScreenView(_ name: String) {
        sendScreenView(name, parameters: [:])
    }

}

class MockAnalyticsRepository: AnalyticsRepository {

    func sendEvent(action: String, parameters: [String: String]) {
        os_log("action: %@, parameters: %@ ", action, String(describing: parameters))
    }

    func sendScreenView(_ name: String, parameters: [String: String]) {
        os_log("Screen view - name: %@, parameters: %@", name, String(describing: parameters))
    }

}

class FirebaseAnalyticsRepository: AnalyticsRepository {
    func sendEvent(action: String, parameters: [String: String]) {
        
        Analytics.logEvent(action, parameters: parameters)
    }

    func sendScreenView(_ name: String, parameters: [String: String]) {
        var extendedParameters = parameters
        extendedParameters[AnalyticsParameterScreenName] = name
        
        Analytics.logEvent(AnalyticsEventScreenView, parameters: extendedParameters)
    }
    
    
}
