"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.
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
const htmlReportGenerator_1 = require("../services/htmlReportGenerator");
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
// Mock Data
const mockSession = {
    id: 'session-12345',
    traceId: 'trace-abc-789',
    question: 'Analyze the scrolling jank in com.example.app',
    currentIteration: 3,
    createdAt: new Date(),
    collectedResults: [
        {
            sql: 'SELECT * FROM slice WHERE name LIKE "%jank%" LIMIT 5',
            result: {
                rowCount: 5,
                durationMs: 42,
                columns: ['name', 'ts', 'dur', 'cpu'],
                rows: [
                    ['frame_draw', 100000, 16000000, 1],
                    ['frame_draw', 116000, 22000000, 1],
                    ['frame_draw', 138000, 16000000, 2],
                    ['frame_draw', 154000, 15000000, 1],
                    ['frame_draw', 170000, 33000000, 3],
                ],
            },
            insight: 'Found multiple janky frames > 16ms',
            timestamp: Date.now() - 5000,
            stepNumber: 1,
        }
    ],
    skillEngineResult: {
        skillId: 'scrolling_analysis',
        skillName: 'Scrolling Analysis',
        executionTimeMs: 1250,
        diagnostics: [
            { severity: 'critical', message: 'Severe jank detected due to long main thread processing', suggestions: ['Check view measurement', 'Optimize layouts'] },
            { severity: 'warning', message: 'Binder transactions on main thread', suggestions: ['Move IPC to background'] }
        ],
        layeredResult: {
            metadata: { skillName: 'Scrolling Analysis', version: '1.0', executedAt: new Date().toISOString() },
            layers: {
                overview: {
                    'jank_rate': 0.15,
                    'avg_fps': 55.4,
                    'max_frame_duration': 42.5
                },
                list: {
                    'janky_frames': [
                        { frame_id: 1, duration: 22.0, type: 'Jank', ts: 116000 },
                        { frame_id: 2, duration: 33.0, type: 'Big Jank', ts: 170000 }
                    ]
                },
                deep: {
                    'frame_details': [
                        {
                            title: 'Frame #1 (22.0ms)',
                            severity: 'medium',
                            jank_type: 'Main Thread',
                            root_cause: {
                                primary: 'View Inflation',
                                method: 'inflate',
                                duration: 12.5
                            },
                            breakdown: {
                                measure: 5.0,
                                layout: 4.0,
                                draw: 3.5
                            }
                        },
                        {
                            title: 'Frame #2 (33.0ms)',
                            severity: 'high',
                            jank_type: 'Binder',
                            binder_tx: {
                                service: 'activity_manager',
                                duration: 18.2,
                                count: 3
                            },
                            cpu_state: {
                                freq: 'low',
                                core: 'little'
                            }
                        }
                    ]
                }
            }
        }
    }
};
const mockFinalAnswer = `
## Analysis Conclusion
The trace analysis confirms **significant jank** during the scrolling session.

1. **Jank Rate**: 15% of frames missed the deadline.
2. **Main Cause**: Expensive view inflation on the main thread and blocking Binder calls.

### Recommendations
- Optimize \`RecyclerView\` item layouts.
- Move \`activity_manager\` IPC calls to a background thread.
`;
async function run() {
    console.log('Generating test HTML report...');
    const generator = (0, htmlReportGenerator_1.getHTMLReportGenerator)();
    const html = generator.generateFromSession(mockSession, mockFinalAnswer);
    const outputPath = path.join(process.cwd(), 'test_report_optimized.html');
    fs.writeFileSync(outputPath, html);
    console.log(`Report generated at: ${outputPath}`);
}
run().catch(console.error);
//# sourceMappingURL=testHtmlReportGen.js.map