/**
 * Framework detection utilities
 */
/**
 * Detect which framework is being used
 */
export function detectFramework(app) {
    // Express detection
    if (app && typeof app === 'function') {
        if (app._router || (app.lazyrouter && typeof app.lazyrouter === 'function')) {
            return { name: 'express', confidence: 1.0 };
        }
    }
    // Next.js detection
    try {
        const fs = require('fs');
        const path = require('path');
        // Check for Next.js Pages Router
        if (fs.existsSync(path.join(process.cwd(), 'pages'))) {
            const hasApiFolder = fs.existsSync(path.join(process.cwd(), 'pages', 'api'));
            if (hasApiFolder) {
                return { name: 'nextjs-pages', confidence: 0.9 };
            }
        }
        // Check for Next.js App Router
        if (fs.existsSync(path.join(process.cwd(), 'app'))) {
            return { name: 'nextjs-app', confidence: 0.9 };
        }
        // Check for next.config
        if (fs.existsSync(path.join(process.cwd(), 'next.config.js')) ||
            fs.existsSync(path.join(process.cwd(), 'next.config.mjs'))) {
            return { name: 'nextjs-pages', confidence: 0.7 };
        }
    }
    catch (e) {
        // Ignore fs errors
    }
    // Vite detection
    try {
        require.resolve('vite');
        return { name: 'vite', confidence: 0.8 };
    }
    catch (e) {
        // Vite not installed
    }
    // React Router detection
    try {
        require.resolve('react-router-dom');
        return { name: 'react-router', confidence: 0.7 };
    }
    catch (e) {
        // React Router not installed
    }
    // Node HTTP detection
    try {
        const http = require('http');
        if (http) {
            return { name: 'node-http', confidence: 0.5 };
        }
    }
    catch (e) {
        // HTTP module not available
    }
    return { name: 'unknown', confidence: 0 };
}
