"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.getEntityDescriptor = getEntityDescriptor;
exports.getEntityParamKey = getEntityParamKey;
exports.getEntityLabel = getEntityLabel;
exports.getEntityIdFieldKeys = getEntityIdFieldKeys;
exports.getEntityDrillDownStrategy = getEntityDrillDownStrategy;
exports.buildEntityLabel = buildEntityLabel;
exports.getCaptureStepPatterns = getCaptureStepPatterns;
exports.resolveCaptureEntityKindByStepId = resolveCaptureEntityKindByStepId;
const ENTITY_DESCRIPTORS = {
    frame: {
        type: 'frame',
        paramKey: 'frame_id',
        label: '帧',
        idFieldKeys: ['frame_id', 'frameId'],
        drillDownStrategy: 'frame_drill_down',
    },
    session: {
        type: 'session',
        paramKey: 'session_id',
        label: '滑动会话',
        idFieldKeys: ['session_id', 'sessionId'],
        drillDownStrategy: 'session_drill_down',
    },
    startup: {
        type: 'startup',
        paramKey: 'startup_id',
        label: '启动事件',
        idFieldKeys: ['startup_id', 'startupId'],
        drillDownStrategy: 'startup_drill_down',
    },
    process: {
        type: 'process',
        paramKey: 'process_name',
        label: '进程',
        idFieldKeys: ['process_name', 'processName', 'package'],
    },
    binder_call: {
        type: 'binder_call',
        paramKey: 'binder_txn_id',
        label: 'Binder 调用',
        idFieldKeys: ['binder_txn_id', 'binderTxnId', 'transaction_id', 'transactionId'],
    },
    time_range: {
        type: 'time_range',
        paramKey: 'time_range',
        label: '时间范围',
        idFieldKeys: ['time_range', 'timeRange'],
    },
};
const ENTITY_CAPTURE_STEP_PATTERNS = {
    frame: ['get_app_jank_frames', 'batch_frame_root_cause', 'jank_frames', 'frame_list', 'frames'],
    session: ['scroll_sessions', 'sessions', 'session_list'],
    cpu_slice: ['cpu_slices', 'sched_slices', 'thread_slices', 'scheduling', 'cpu_timeline'],
    binder: ['binder_transactions', 'binder_calls', 'ipc_transactions', 'binder_blocking'],
    gc: ['gc_events', 'garbage_collection', 'gc_analysis', 'gc_pauses'],
    memory: ['memory_events', 'allocations', 'oom_events', 'lmk_events', 'memory_stats'],
};
function getEntityDescriptor(type) {
    return ENTITY_DESCRIPTORS[type];
}
function getEntityParamKey(type) {
    return ENTITY_DESCRIPTORS[type].paramKey;
}
function getEntityLabel(type) {
    return ENTITY_DESCRIPTORS[type].label;
}
function getEntityIdFieldKeys(type) {
    return [...ENTITY_DESCRIPTORS[type].idFieldKeys];
}
function getEntityDrillDownStrategy(type) {
    return ENTITY_DESCRIPTORS[type].drillDownStrategy;
}
function buildEntityLabel(type, entityId) {
    return `${getEntityLabel(type)} ${String(entityId)}`;
}
function getCaptureStepPatterns(kind) {
    return ENTITY_CAPTURE_STEP_PATTERNS[kind];
}
function resolveCaptureEntityKindByStepId(stepId, matchMode = 'exact') {
    const normalizedStepId = String(stepId || '').trim().toLowerCase();
    if (!normalizedStepId)
        return null;
    for (const kind of Object.keys(ENTITY_CAPTURE_STEP_PATTERNS)) {
        const patterns = ENTITY_CAPTURE_STEP_PATTERNS[kind];
        for (const pattern of patterns) {
            const normalizedPattern = pattern.toLowerCase();
            if (matchMode === 'exact' && normalizedStepId === normalizedPattern) {
                return kind;
            }
            if (matchMode === 'contains' && normalizedStepId.includes(normalizedPattern)) {
                return kind;
            }
        }
    }
    return null;
}
//# sourceMappingURL=entityRegistry.js.map