"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const express_1 = require("express");
const database_1 = require("../../../06-memory/database/database");
const router = (0, express_1.Router)();
// Project list
router.get('/project/list', (_req, res) => {
    const db = (0, database_1.getDb)();
    const rows = db.prepare('SELECT * FROM projects ORDER BY updated_at DESC').all();
    res.json({ projects: rows });
});
// Project profile
router.get('/project/profile/:projectId', (req, res) => {
    const db = (0, database_1.getDb)();
    const row = db.prepare('SELECT * FROM projects WHERE name = ?').get(req.params.projectId);
    if (!row) {
        res.status(404).json({ error: 'not found' });
        return;
    }
    res.json(row);
});
// Project DNA
router.get('/project/dna-list', (_req, res) => {
    const db = (0, database_1.getDb)();
    try {
        const rows = db.prepare('SELECT * FROM projects ORDER BY name').all();
        res.json({ projects: rows });
    }
    catch {
        res.json({ projects: [] });
    }
});
// Graph stats
router.get('/graph/stats', (_req, res) => {
    const db = (0, database_1.getDb)();
    try {
        const files = db.prepare('SELECT COUNT(*) as count FROM knowledge_graph_files').get();
        const deps = db.prepare('SELECT COUNT(*) as count FROM knowledge_graph_deps').get();
        const entities = db.prepare('SELECT COUNT(*) as count FROM graph_entities').get();
        res.json({ files: files.count, dependencies: deps.count, entities: entities.count });
    }
    catch {
        res.json({ files: 0, dependencies: 0, entities: 0 });
    }
});
// Graph full
router.get('/graph/full', (_req, res) => {
    const db = (0, database_1.getDb)();
    try {
        const files = db.prepare('SELECT * FROM knowledge_graph_files ORDER BY risk_score DESC LIMIT 50').all();
        const deps = db.prepare('SELECT * FROM knowledge_graph_deps LIMIT 100').all();
        res.json({ files, dependencies: deps });
    }
    catch {
        res.json({ files: [], dependencies: [] });
    }
});
exports.default = router;
//# sourceMappingURL=project.js.map