"use strict";
/**
 * Cross-ecosystem package manager detection.
 *
 * Provides a common interface (PackageManagerDetector) that each FrameworkConfig
 * implements, plus shared helpers for Node.js, Python, PHP, and Swift ecosystems.
 * The MCP tool in wizard-tools.ts delegates to whatever detector the
 * current framework supplies.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.detectNodePackageManagers = detectNodePackageManagers;
exports.detectPythonPackageManagers = detectPythonPackageManagers;
exports.composerPackageManager = composerPackageManager;
exports.swiftPackageManager = swiftPackageManager;
exports.detectJavaPackageManagers = detectJavaPackageManagers;
exports.flutterPackageManager = flutterPackageManager;
exports.goPackageManager = goPackageManager;
exports.unityPackageManager = unityPackageManager;
exports.unrealPackageManager = unrealPackageManager;
exports.bundlerPackageManager = bundlerPackageManager;
exports.gradlePackageManager = gradlePackageManager;
const utils_1 = require("../frameworks/python/utils");
const package_manager_detection_light_1 = require("./package-manager-detection-light");
// ---------------------------------------------------------------------------
// Node.js helper
//
// Delegates to the dependency-free `detectNodePackageManagersLight` so both
// the heavy and light call sites stay in sync. Detection cold paths should
// import the light version directly (see `src/lib/package-manager-detection-light.ts`).
// ---------------------------------------------------------------------------
function detectNodePackageManagers(installDir) {
    return (0, package_manager_detection_light_1.detectNodePackageManagersLight)(installDir);
}
// ---------------------------------------------------------------------------
// Python helper
// ---------------------------------------------------------------------------
const PYTHON_PM_INFO = {
    [utils_1.PythonPackageManager.UV]: {
        name: 'uv',
        label: 'uv',
        installCommand: 'uv add',
        runCommand: 'uv run',
    },
    [utils_1.PythonPackageManager.POETRY]: {
        name: 'poetry',
        label: 'Poetry',
        installCommand: 'poetry add',
        runCommand: 'poetry run',
    },
    [utils_1.PythonPackageManager.PDM]: {
        name: 'pdm',
        label: 'PDM',
        installCommand: 'pdm add',
        runCommand: 'pdm run',
    },
    [utils_1.PythonPackageManager.HATCH]: {
        name: 'hatch',
        label: 'Hatch',
        installCommand: 'hatch add',
        runCommand: 'hatch run',
    },
    [utils_1.PythonPackageManager.RYE]: {
        name: 'rye',
        label: 'Rye',
        installCommand: 'rye add',
        runCommand: 'rye run',
    },
    [utils_1.PythonPackageManager.PIPENV]: {
        name: 'pipenv',
        label: 'Pipenv',
        installCommand: 'pipenv install',
        runCommand: 'pipenv run',
    },
    [utils_1.PythonPackageManager.CONDA]: {
        name: 'conda',
        label: 'Conda',
        installCommand: 'conda install',
        runCommand: 'conda run',
    },
    [utils_1.PythonPackageManager.PIP]: {
        name: 'pip',
        label: 'pip',
        installCommand: 'pip install',
    },
    [utils_1.PythonPackageManager.UNKNOWN]: {
        name: 'pip',
        label: 'pip (default)',
        installCommand: 'pip install',
    },
};
/**
 * Detect Python package managers via lockfiles and config files.
 * Wraps the existing detectPackageManager() from python/utils.ts.
 */
async function detectPythonPackageManagers(installDir) {
    const pm = await (0, utils_1.detectPackageManager)({
        installDir,
    });
    const info = PYTHON_PM_INFO[pm];
    return {
        detected: [info],
        primary: info,
        recommendation: `Use ${info.label} (${info.installCommand}).`,
    };
}
// ---------------------------------------------------------------------------
// PHP (Composer) helper
// ---------------------------------------------------------------------------
const COMPOSER = {
    name: 'composer',
    label: 'Composer',
    installCommand: 'composer require',
};
function composerPackageManager() {
    return Promise.resolve({
        detected: [COMPOSER],
        primary: COMPOSER,
        recommendation: 'Use Composer (composer require).',
    });
}
// ---------------------------------------------------------------------------
// Swift (SPM) helper
// ---------------------------------------------------------------------------
const SPM = {
    name: 'spm',
    label: 'Swift Package Manager',
    installCommand: 'swift package add-dependency',
};
function swiftPackageManager() {
    return Promise.resolve({
        detected: [SPM],
        primary: SPM,
        recommendation: 'Use Swift Package Manager. Add the dependency to Package.swift or via Xcode.',
    });
}
// ---------------------------------------------------------------------------
// Java (Maven / Gradle) helper
// ---------------------------------------------------------------------------
const MAVEN = {
    name: 'maven',
    label: 'Maven',
    installCommand: 'mvn',
    runCommand: 'mvn exec:java',
};
const GRADLE_JAVA = {
    name: 'gradle',
    label: 'Gradle',
    installCommand: 'gradle',
    runCommand: 'gradle run',
};
async function detectJavaPackageManagers(installDir) {
    const fs = await import('node:fs');
    const nodePath = await import('node:path');
    const hasMaven = fs.existsSync(nodePath.join(installDir, 'pom.xml'));
    const hasGradle = fs.existsSync(nodePath.join(installDir, 'build.gradle')) ||
        fs.existsSync(nodePath.join(installDir, 'build.gradle.kts'));
    if (hasMaven) {
        return {
            detected: [MAVEN],
            primary: MAVEN,
            recommendation: 'Use Maven: add the dependency to pom.xml and run mvn install.',
        };
    }
    if (hasGradle) {
        return {
            detected: [GRADLE_JAVA],
            primary: GRADLE_JAVA,
            recommendation: 'Use Gradle: add the implementation dependency to build.gradle and sync.',
        };
    }
    return {
        detected: [MAVEN],
        primary: MAVEN,
        recommendation: 'No build file detected. Defaulting to Maven.',
    };
}
// ---------------------------------------------------------------------------
// Flutter (pub) helper
// ---------------------------------------------------------------------------
const FLUTTER_PUB = {
    name: 'flutter',
    label: 'Flutter pub',
    installCommand: 'flutter pub add',
    runCommand: 'flutter pub run',
};
function flutterPackageManager() {
    return Promise.resolve({
        detected: [FLUTTER_PUB],
        primary: FLUTTER_PUB,
        recommendation: 'Use Flutter pub (flutter pub add).',
    });
}
// ---------------------------------------------------------------------------
// Go (modules) helper
// ---------------------------------------------------------------------------
const GO_MODULES = {
    name: 'go',
    label: 'Go modules',
    installCommand: 'go get',
    runCommand: 'go run',
};
function goPackageManager() {
    return Promise.resolve({
        detected: [GO_MODULES],
        primary: GO_MODULES,
        recommendation: 'Use Go modules (go get).',
    });
}
// ---------------------------------------------------------------------------
// Unity (UPM) helper
// ---------------------------------------------------------------------------
const UNITY_UPM = {
    name: 'unity',
    label: 'Unity Package Manager',
    installCommand: 'Add to Packages/manifest.json dependencies: "com.amplitude.unity-plugin": "https://github.com/amplitude/unity-plugin.git?path=/Assets"',
};
function unityPackageManager() {
    return Promise.resolve({
        detected: [UNITY_UPM],
        primary: UNITY_UPM,
        recommendation: 'Use Unity Package Manager: add the git URL dependency to Packages/manifest.json.',
    });
}
// ---------------------------------------------------------------------------
// Unreal Engine helper
// ---------------------------------------------------------------------------
const UNREAL_MANUAL = {
    name: 'unreal',
    label: 'Manual plugin install',
    installCommand: 'Download AmplitudeUnreal.zip from https://github.com/amplitude/Amplitude-Unreal/releases/latest and extract into Plugins/AmplitudeUnreal/',
};
function unrealPackageManager() {
    return Promise.resolve({
        detected: [UNREAL_MANUAL],
        primary: UNREAL_MANUAL,
        recommendation: 'Unreal Engine uses manual plugin installation. Download the zip from GitHub releases and extract it into the project Plugins/ directory.',
    });
}
// ---------------------------------------------------------------------------
// Ruby (Bundler) helper
// ---------------------------------------------------------------------------
const BUNDLER = {
    name: 'bundler',
    label: 'Bundler',
    installCommand: 'bundle add',
    runCommand: 'bundle exec',
};
function bundlerPackageManager() {
    return Promise.resolve({
        detected: [BUNDLER],
        primary: BUNDLER,
        recommendation: 'Use Bundler (bundle add). Run commands with bundle exec.',
    });
}
// ---------------------------------------------------------------------------
// Android (Gradle) helper
// ---------------------------------------------------------------------------
const GRADLE = {
    name: 'gradle',
    label: 'Gradle',
    installCommand: 'implementation',
};
function gradlePackageManager() {
    return Promise.resolve({
        detected: [GRADLE],
        primary: GRADLE,
        recommendation: 'Add dependencies to build.gradle(.kts) using implementation().',
    });
}
