// ci-generator/context-builders.ts — Build CIStackContext per ecosystem (SPEC-066)
import { detectNodePackageManager, detectNodeVersion, buildNodeCommands, detectPythonPackageManager, detectPythonVersion, detectGoVersion, detectRustChannel, detectJavaVersion, detectJavaBuildTool, } from './stack-detector.js';
/** Build context for Node.js/TypeScript projects. */
async function buildNodeContext(projectPath, hasDocker) {
    const pm = await detectNodePackageManager(projectPath);
    const nodeVersion = await detectNodeVersion(projectPath);
    const cmds = buildNodeCommands(pm);
    return {
        ecosystem: 'nodejs',
        language: 'typescript',
        packageManager: pm,
        testCommand: cmds.test,
        lintCommand: cmds.lint,
        buildCommand: cmds.build,
        hasDocker,
        nodeVersion,
    };
}
/** Build context for Python projects. */
async function buildPythonContext(projectPath, hasDocker) {
    const pm = await detectPythonPackageManager(projectPath);
    const pythonVersion = await detectPythonVersion(projectPath);
    const lintCmd = pm === 'uv' ? 'uv run ruff check .' : 'ruff check .';
    const testCmd = pm === 'poetry' ? 'poetry run pytest' : pm === 'uv' ? 'uv run pytest' : 'pytest';
    const buildCmd = pm === 'poetry' ? 'poetry build' : pm === 'uv' ? 'uv build' : 'python -m build';
    return {
        ecosystem: 'python',
        language: 'python',
        packageManager: pm,
        testCommand: testCmd,
        lintCommand: lintCmd,
        buildCommand: buildCmd,
        hasDocker,
        pythonVersion,
    };
}
/** Build context for JVM-based projects (Java/Kotlin). */
async function buildJvmContext(ecosystem, projectPath, hasDocker) {
    const javaVersion = await detectJavaVersion(projectPath);
    const javaBuildTool = await detectJavaBuildTool(projectPath);
    const isMaven = javaBuildTool === 'maven';
    return {
        ecosystem,
        language: ecosystem,
        packageManager: javaBuildTool,
        testCommand: isMaven ? 'mvn test' : './gradlew test',
        lintCommand: isMaven ? 'mvn checkstyle:check' : './gradlew checkstyleMain',
        buildCommand: isMaven ? 'mvn package -DskipTests' : './gradlew build -x test',
        hasDocker,
        javaVersion,
        javaDistribution: 'temurin',
        javaBuildTool,
    };
}
// -- Static ecosystem configs (no async detection needed) ---------------------
const STATIC_ECOSYSTEMS = {
    go: ['go', 'go mod', 'go test ./...', 'golangci-lint run', 'go build ./...'],
    rust: ['rust', 'cargo', 'cargo test', 'cargo clippy -- -D warnings', 'cargo build --release'],
    ruby: ['ruby', 'bundler', 'bundle exec rspec', 'bundle exec rubocop', 'gem build *.gemspec'],
    php: [
        'php',
        'composer',
        'vendor/bin/phpunit',
        'vendor/bin/phpstan analyse',
        'composer install --no-dev --optimize-autoloader',
    ],
    dart: ['dart', 'pub', 'flutter test', 'dart analyze', 'flutter build'],
    dotnet: [
        'csharp',
        'nuget',
        'dotnet test',
        'dotnet format --verify-no-changes',
        'dotnet build --configuration Release',
    ],
    unknown: [
        'unknown',
        'unknown',
        'echo "No test command configured"',
        'echo "No lint command configured"',
        'echo "No build command configured"',
    ],
};
function buildStaticContext(ecosystem, hasDocker) {
    const cfg = STATIC_ECOSYSTEMS[ecosystem];
    /* v8 ignore next 5 */
    const lang = cfg?.[0] ?? 'unknown';
    const pm = cfg?.[1] ?? 'unknown';
    const test = cfg?.[2] ?? 'echo "No test command configured"';
    const lint = cfg?.[3] ?? 'echo "No lint command configured"';
    const build = cfg?.[4] ?? 'echo "No build command configured"';
    return {
        ecosystem,
        language: lang,
        packageManager: pm,
        testCommand: test,
        lintCommand: lint,
        buildCommand: build,
        hasDocker,
    };
}
/** Build a CIStackContext for the detected ecosystem. */
export async function buildContextForEcosystem(ecosystem, projectPath, hasDocker) {
    switch (ecosystem) {
        case 'nodejs':
            return buildNodeContext(projectPath, hasDocker);
        case 'python':
            return buildPythonContext(projectPath, hasDocker);
        case 'go':
            return {
                ...buildStaticContext(ecosystem, hasDocker),
                goVersion: await detectGoVersion(projectPath),
            };
        case 'rust':
            return {
                ...buildStaticContext(ecosystem, hasDocker),
                rustChannel: await detectRustChannel(projectPath),
            };
        case 'java':
        case 'kotlin':
            return buildJvmContext(ecosystem, projectPath, hasDocker);
        case 'ruby':
        case 'php':
        case 'dart':
        case 'dotnet':
        case 'unknown':
            return buildStaticContext(ecosystem, hasDocker);
    }
}
//# sourceMappingURL=context-builders.js.map