"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.registerAgentQuickSceneRoutes = registerAgentQuickSceneRoutes;
const auth_1 = require("../middleware/auth");
const resourceOwnership_1 = require("../services/resourceOwnership");
const traceMetadataStore_1 = require("../services/traceMetadataStore");
const traceProcessorService_1 = require("../services/traceProcessorService");
function registerAgentQuickSceneRoutes(router, deps) {
    router.post('/scene-detect-quick', async (req, res) => {
        try {
            const { traceId } = req.body;
            if (!traceId) {
                return res.status(400).json({
                    success: false,
                    error: 'traceId is required',
                });
            }
            if (!await (0, traceMetadataStore_1.readTraceMetadataForContext)(traceId, (0, auth_1.requireRequestContext)(req))) {
                return (0, resourceOwnership_1.sendResourceNotFound)(res, 'Trace not found in backend');
            }
            const traceProcessorService = (0, traceProcessorService_1.getTraceProcessorService)();
            const trace = await traceProcessorService.getOrLoadTrace(traceId);
            if (!trace) {
                return res.status(404).json({
                    success: false,
                    error: 'Trace not found in backend',
                    hint: 'Please upload the trace to the backend first',
                    code: 'TRACE_NOT_UPLOADED',
                });
            }
            console.log('[AgentRoutes] Quick scene detection for traceId:', traceId);
            const scenes = await deps.detectScenesQuick(traceProcessorService, traceId);
            console.log('[AgentRoutes] Quick scene detection complete:', scenes.length, 'scenes');
            return res.json({
                success: true,
                scenes,
            });
        }
        catch (error) {
            console.error('[AgentRoutes] Quick scene detection error:', error);
            return res.status(500).json({
                success: false,
                error: error.message || 'Quick scene detection failed',
            });
        }
    });
}
//# sourceMappingURL=agentQuickSceneRoutes.js.map