import ContentsquareModule
import Foundation
import UIKit

@objc(CDVContentsquareTelemetry)
class ContentsquareCAPTelemetry: NSObject {
    
    private let XPF_TYPE = "CAPACITOR"
    private let UNKNOWN_XPF_VERSION = "UNKNOWN"
    
    
    func collect(name: String, value: String) {
        let selectorCollect = NSSelectorFromString("_telemetryCollect:withValue:")
        if Contentsquare.responds(to: selectorCollect) {
            _ = Contentsquare.perform(selectorCollect, with: name, with: value)
        }
    }
    
    func setXPFVersion(capacitorVersion: String) {
        let selectorVersion = NSSelectorFromString("_telemetrySetXPFVersion:")
        if Contentsquare.responds(to: selectorVersion) {
            _ = Contentsquare.perform(selectorVersion, with: capacitorVersion)
        }
    }
    
    func setXPFType() {
        let selectorType = NSSelectorFromString("_telemetrySetXPFType:")
        if Contentsquare.responds(to: selectorType) {
            _ = Contentsquare.perform(selectorType, with: XPF_TYPE)
        }
    }
    
    private func getCapacitorVersion() -> String {
        return UNKNOWN_XPF_VERSION
    }
    
}
