"use strict";
/**
 * Route Discovery Orchestrator
 *
 * Runs all framework-specific route extractors, deduplicates routes,
 * and builds the unified RouteMap.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.createEmptyRouteMap = void 0;
exports.discoverRoutes = discoverRoutes;
const express_1 = require("./express");
const nextjs_1 = require("./nextjs");
const python_1 = require("./python");
var types_1 = require("./types");
Object.defineProperty(exports, "createEmptyRouteMap", { enumerable: true, get: function () { return types_1.createEmptyRouteMap; } });
/**
 * Discover all routes across all supported frameworks.
 *
 * Runs Express, Next.js, and Python extractors, deduplicates,
 * and builds the fileToRoutes index.
 */
function discoverRoutes(files, frameworkPrimary) {
    const allRoutes = [];
    const allMountPoints = [];
    for (const file of files) {
        // Express/Fastify/Hono/Koa
        const expressRoutes = (0, express_1.extractExpressRoutes)(file.content, file.path);
        allRoutes.push(...expressRoutes);
        const mounts = (0, express_1.extractMountPoints)(file.content, file.path);
        allMountPoints.push(...mounts);
        // Python (Flask/Django)
        const pythonRoutes = (0, python_1.extractPythonRoutes)(file.content, file.path);
        allRoutes.push(...pythonRoutes);
    }
    // Next.js (needs all files at once for filesystem-based routing)
    const nextjsRoutes = (0, nextjs_1.extractNextJSRoutes)(files, frameworkPrimary);
    allRoutes.push(...nextjsRoutes);
    // Deduplicate: same file + path + method combo
    const deduped = deduplicateRoutes(allRoutes);
    // Build fileToRoutes index
    const fileToRoutes = new Map();
    for (const route of deduped) {
        const existing = fileToRoutes.get(route.filePath) || [];
        existing.push(route);
        fileToRoutes.set(route.filePath, existing);
    }
    return {
        routeMap: { routes: deduped, fileToRoutes },
        mountPoints: allMountPoints,
    };
}
// ============================================================================
// Internal Helpers
// ============================================================================
function deduplicateRoutes(routes) {
    const seen = new Set();
    const result = [];
    for (const route of routes) {
        const key = `${route.filePath}:${route.path}:${[...route.methods].sort().join(',')}`;
        if (!seen.has(key)) {
            seen.add(key);
            result.push(route);
        }
    }
    return result;
}
//# sourceMappingURL=index.js.map