"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 {
    trackApplicationStart(startTime, apiVersion) {
        if (this.reporter !== undefined) {
            this.reporter.sendTelemetryEvent('application_start', {
                duration: perf_hooks_1.performance.now() - startTime,
                tool: process.env.SFDX_TOOL,
                apiVersion
            });
        }
    }
    trackApplicationStartException(exception) {
        if (this.reporter) {
            this.reporter.sendTelemetryEvent('application_start_exception', {
                exception: exception.toString()
            });
        }
    }
    trackApplicationStartError(error) {
        if (this.reporter) {
            this.reporter.sendTelemetryEvent('application_start_exception', {
                exception: error
            });
        }
    }
    trackApplicationStartNoAuth() {
        if (this.reporter) {
            this.reporter.sendTelemetryEvent('application_start_noauth');
        }
    }
    trackApplicationEnd(startTime) {
        if (this.reporter) {
            this.reporter.sendTelemetryEvent('application_end', {
                runtimeDuration: perf_hooks_1.performance.now() - startTime
            });
        }
    }
    trackComponentPreview(container, duration, apiVersion, browser, liveReload) {
        if (this.reporter) {
            this.reporter.sendTelemetryEvent('component_preview', {
                container,
                duration,
                apiVersion,
                browser,
                liveReload: liveReload.toString()
            });
        }
    }
    trackComponentPreviewException(exception, apiVersion) {
        if (this.reporter) {
            this.reporter.sendTelemetryEvent('component_preview_exception', {
                exception: exception.toString(),
                apiVersion
            });
        }
    }
    trackComponentCompileException(exception) {
        if (this.reporter) {
            this.reporter.sendTelemetryEvent('component_compile_exception', {
                exception: exception.toString()
            });
        }
    }
    trackNonSfdxProjectUsage() {
        if (this.reporter) {
            this.reporter.sendTelemetryEvent('application_start_non_sfdx_project');
        }
    }
    trackMissingDependentComponent() {
        if (this.reporter) {
            this.reporter.sendTelemetryEvent('missing_dependent_component');
        }
    }
    static getInstance() {
        if (!LocalDevTelemetryReporter._instance) {
            LocalDevTelemetryReporter._instance = new LocalDevTelemetryReporter();
        }
        return LocalDevTelemetryReporter._instance;
    }
    async initializeService(sessionNonce) {
        const userId = machineId_1.getMachineId();
        this.reporter = await telemetryReporter_1.TelemetryReporter.create(new LocalDevTelemetryOptions_1.default(userId, sessionNonce));
    }
    setReporter(reporter) {
        this.reporter = reporter;
    }
}
exports.default = LocalDevTelemetryReporter;
//# sourceMappingURL=LocalDevTelemetryReporter.js.map