"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.ContainerEventTelemetryProducer = void 0;
const uuid_1 = require("uuid");
const containerSystemEvents_js_1 = require("./containerSystemEvents.js");
const containerTelemetry_js_1 = require("./containerTelemetry.js");
/**
 * This class produces {@link IContainerTelemetry} from raw container system events {@link @fluidframework/fluid-static#IFluidContainerEvents}.
 * The class contains different helper methods for simplifying and standardizing logic for adding additional information necessary
 * to produce different {@link IContainerTelemetry}.
 */
class ContainerEventTelemetryProducer {
    constructor(containerId) {
        this.containerId = containerId;
        /**
         * Unique identifier for the instance of the container that this class is generating telemetry for.
         */
        this.containerInstanceId = (0, uuid_1.v4)();
        this.produceHeartbeatTelemetry = () => {
            return {
                eventName: "fluidframework.container.heartbeat",
                containerId: this.containerId,
                containerInstanceId: this.containerInstanceId,
            };
        };
        this.produceBaseContainerTelemetry = (eventName) => {
            return {
                eventName,
                containerId: this.containerId,
                containerInstanceId: this.containerInstanceId,
            };
        };
        this.produceDiposedTelemetry = (payload) => {
            const telemetry = {
                eventName: containerTelemetry_js_1.ContainerTelemetryEventNames.DISPOSED,
                containerId: this.containerId,
                containerInstanceId: this.containerInstanceId,
            };
            if (payload?.error !== undefined) {
                telemetry.error = payload.error;
            }
            return telemetry;
        };
    }
    produceFromSystemEvent(eventName, payload) {
        switch (eventName) {
            case containerSystemEvents_js_1.IFluidContainerSystemEventNames.CONNECTED: {
                return this.produceBaseContainerTelemetry(containerTelemetry_js_1.ContainerTelemetryEventNames.CONNECTED);
            }
            case containerSystemEvents_js_1.IFluidContainerSystemEventNames.DISCONNECTED: {
                return this.produceBaseContainerTelemetry(containerTelemetry_js_1.ContainerTelemetryEventNames.DISCONNECTED);
            }
            case containerSystemEvents_js_1.IFluidContainerSystemEventNames.DISPOSED: {
                const typedPayload = payload;
                return this.produceDiposedTelemetry(typedPayload);
            }
            default: {
                break;
            }
        }
    }
}
exports.ContainerEventTelemetryProducer = ContainerEventTelemetryProducer;
//# sourceMappingURL=telemetryProducer.js.map