"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const LocalDevTelemetryOptions_1 = __importDefault(require("./LocalDevTelemetryOptions"));
const machineId_1 = require("./machineId");
const telemetryReporter_1 = require("@salesforce/telemetry/lib/telemetryReporter");
const perf_hooks_1 = require("perf_hooks");
class LocalDevTelemetryReporter {
    constructor(reporter) {
        this.reporter = reporter;
    }
    trackApplicationStart(startTime, apiVersion) {
        this.reporter.sendTelemetryEvent('application_start', {
            duration: perf_hooks_1.performance.now() - startTime,
            tool: process.env.SFDX_TOOL,
            apiVersion
        });
    }
    trackApplicationStartException(exception) {
        this.reporter.sendTelemetryEvent('application_start_exception', {
            exception: exception.toString()
        });
    }
    trackApplicationStartNoAuth() {
        this.reporter.sendTelemetryEvent('application_start_noauth');
    }
    trackApplicationEnd(startTime) {
        this.reporter.sendTelemetryEvent('application_end', {
            runtimeDuration: perf_hooks_1.performance.now() - startTime
        });
    }
    trackComponentPreview(container, duration, apiVersion, browser, liveReload) {
        this.reporter.sendTelemetryEvent('component_preview', {
            container,
            duration,
            apiVersion,
            browser,
            liveReload: liveReload.toString()
        });
    }
    trackComponentPreviewException(exception, apiVersion) {
        this.reporter.sendTelemetryEvent('component_preview_exception', {
            exception: exception.toString(),
            apiVersion
        });
    }
    trackComponentCompileException(exception) {
        this.reporter.sendTelemetryEvent('component_compile_exception', {
            exception: exception.toString()
        });
    }
    static async getInstance(sessionId) {
        const userId = machineId_1.getMachineId();
        const reporter = await telemetryReporter_1.TelemetryReporter.create(new LocalDevTelemetryOptions_1.default(userId, sessionId));
        return new LocalDevTelemetryReporter(reporter);
    }
}
exports.default = LocalDevTelemetryReporter;
LocalDevTelemetryReporter._instance = null;
//# sourceMappingURL=LocalDevTelemetryReporter.js.map