/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { v4 as uuid } from "uuid";
import { IFluidContainerSystemEventNames, } from "./containerSystemEvents.js";
import { ContainerTelemetryEventNames, } from "./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}.
 */
export class ContainerEventTelemetryProducer {
    constructor(containerId) {
        this.containerId = containerId;
        /**
         * Unique identifier for the instance of the container that this class is generating telemetry for.
         */
        this.containerInstanceId = uuid();
        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: ContainerTelemetryEventNames.DISPOSED,
                containerId: this.containerId,
                containerInstanceId: this.containerInstanceId,
            };
            if (payload?.error !== undefined) {
                telemetry.error = payload.error;
            }
            return telemetry;
        };
    }
    produceFromSystemEvent(eventName, payload) {
        switch (eventName) {
            case IFluidContainerSystemEventNames.CONNECTED: {
                return this.produceBaseContainerTelemetry(ContainerTelemetryEventNames.CONNECTED);
            }
            case IFluidContainerSystemEventNames.DISCONNECTED: {
                return this.produceBaseContainerTelemetry(ContainerTelemetryEventNames.DISCONNECTED);
            }
            case IFluidContainerSystemEventNames.DISPOSED: {
                const typedPayload = payload;
                return this.produceDiposedTelemetry(typedPayload);
            }
            default: {
                break;
            }
        }
    }
}
//# sourceMappingURL=telemetryProducer.js.map