"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createDependencies = void 0;
const devkit_1 = require("@nx/devkit");
const maven_data_cache_1 = require("./maven-data-cache");
const internal_1 = require("@nx/devkit/internal");
/**
 * Create dependencies between Maven projects by analyzing the createNodesResults
 * Uses in-memory Maven analysis data that was stored by createNodes
 */
const createDependencies = async (options, context) => {
    const mavenData = (0, maven_data_cache_1.getCurrentMavenData)();
    if (!mavenData) {
        devkit_1.logger.verbose('[Maven Dependencies] No Maven data found in workspace:', context.workspaceRoot);
        return [];
    }
    devkit_1.logger.verbose('[Maven Dependencies] Found Maven data with', mavenData.createDependenciesResults.length, 'dependencies');
    // Create a mapping from project root to project name
    const rootToProjectMap = (0, internal_1.createProjectRootMappingsFromProjectConfigurations)(context.projects);
    // Extract and transform dependencies from the mavenData
    const transformedDependencies = mavenData.createDependenciesResults.map((dep) => ({
        ...dep,
        source: dep.source.startsWith('maven:')
            ? dep.source
            : rootToProjectMap.get(dep.source),
        // External deps use maven: prefix — pass through as-is
        target: dep.target.startsWith('maven:')
            ? dep.target
            : rootToProjectMap.get(dep.target),
    }));
    return transformedDependencies;
};
exports.createDependencies = createDependencies;
