"use strict";
// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (C) 2024-2026 Gracker (Chris)
// This file is part of SmartPerfetto. See LICENSE for details.
Object.defineProperty(exports, "__esModule", { value: true });
exports.traceProcessorProcessorKey = traceProcessorProcessorKey;
exports.buildTraceProcessorDatabaseScope = buildTraceProcessorDatabaseScope;
exports.buildTraceProcessorQueryProvenance = buildTraceProcessorQueryProvenance;
function traceProcessorProcessorKey(traceId, leaseId, mode = 'shared') {
    return mode === 'isolated' && leaseId ? `${traceId}:lease:${leaseId}` : traceId;
}
function buildTraceProcessorDatabaseScope(input) {
    const processorKey = traceProcessorProcessorKey(input.traceId, input.leaseId, input.leaseMode);
    const isolation = input.leaseMode === 'isolated' && input.leaseId ? 'isolated' : 'shared';
    return {
        traceId: input.traceId,
        ...(input.traceSide ? { traceSide: input.traceSide } : {}),
        processorKey,
        isolation,
        ...(input.leaseId ? { leaseId: input.leaseId } : {}),
        ...(input.leaseMode ? { leaseMode: input.leaseMode } : {}),
    };
}
function buildTraceProcessorQueryProvenance(input) {
    const databaseScope = buildTraceProcessorDatabaseScope(input);
    const connectionScope = {
        connectionKey: databaseScope.processorKey,
        database: databaseScope,
    };
    return {
        ...(input.traceSide ? { traceSide: input.traceSide } : {}),
        traceId: input.traceId,
        processorKey: databaseScope.processorKey,
        databaseScope,
        connectionScope,
    };
}
//# sourceMappingURL=traceProcessorConnectionModel.js.map