/** Map risk → estimated effort. */
function estimateEffort(migration) {
    if (migration.risk === 'critical' || migration.risk === 'high') {
        return 'days';
    }
    const gap = migration.latestMajor - migration.currentMajor;
    if (gap >= 3) {
        return 'weeks';
    }
    return 'hours';
}
/** Generic steps applicable to any ecosystem upgrade. */
function baseSteps(migration) {
    const { package: pkg, currentMajor, latestMajor } = migration;
    return [
        `Review ${pkg} v${String(latestMajor)} migration guide / changelog`,
        `Create a dedicated branch: upgrade/${pkg}-v${String(latestMajor)}`,
        `Update ${pkg} from v${String(currentMajor)} to v${String(latestMajor)} in the manifest`,
        `Run the test suite — fix all failures before merging`,
        `Update CI/CD pipelines if needed`,
        `Perform smoke testing in a staging environment`,
        `Merge and monitor for regressions`,
    ];
}
/** npm-specific steps. */
function npmSteps(migration) {
    return [
        ...baseSteps(migration),
        `Run \`npm audit\` after upgrading to check for new advisories`,
        `Check for deprecated APIs using \`npx depcheck\``,
    ];
}
/** pypi-specific steps. */
function pypiSteps(migration) {
    return [
        ...baseSteps(migration),
        `Update pyproject.toml / requirements.txt constraints`,
        `Run \`pip-audit\` to verify no new security issues`,
        `Check type stubs (py.typed) compatibility`,
    ];
}
/** cargo-specific steps. */
function cargoSteps(migration) {
    return [
        ...baseSteps(migration),
        `Run \`cargo update ${migration.package}\` to bump Cargo.lock`,
        `Run \`cargo clippy\` and fix all new warnings`,
        `Run \`cargo audit\` to check for advisories`,
    ];
}
/** go-specific steps. */
function goSteps(migration) {
    const { package: pkg, latestMajor } = migration;
    return [
        ...baseSteps(migration),
        `Update import paths to include /v${String(latestMajor)} suffix if required by the module`,
        `Run \`go mod tidy\` after updating go.mod`,
        `Run \`go vet ./...\` and fix all issues`,
        `Verify compatibility with \`govulncheck\` for module: ${pkg}`,
    ];
}
/** maven-specific steps. */
function mavenSteps(migration) {
    return [
        ...baseSteps(migration),
        `Update version in pom.xml / build.gradle`,
        `Run \`mvn dependency:analyze\` to check for unused or missing deps`,
        `Run \`./gradlew dependencyInsight\` for transitive conflicts`,
    ];
}
/** composer-specific steps. */
function composerSteps(migration) {
    return [
        ...baseSteps(migration),
        `Run \`composer update ${migration.package}\``,
        `Run \`composer audit\` to check for security advisories`,
        `Verify PHP version compatibility for the new major`,
    ];
}
/** rubygems-specific steps. */
function rubygemsSteps(migration) {
    return [
        ...baseSteps(migration),
        `Update version constraint in Gemfile for ${migration.package}`,
        `Run \`bundle update ${migration.package}\` to resolve dependencies`,
        `Run \`bundle exec rubocop\` and fix new offenses`,
        `Check for deprecation warnings in the test output`,
    ];
}
/** nuget-specific steps. */
function nugetSteps(migration) {
    return [
        ...baseSteps(migration),
        `Update <PackageReference> Version in .csproj for ${migration.package}`,
        `Run \`dotnet restore\` to fetch the new version`,
        `Run \`dotnet build\` and fix compilation errors`,
        `Run \`dotnet test\` — fix all broken tests before merging`,
    ];
}
/** pub-specific steps (Dart/Flutter). */
function pubSteps(migration) {
    return [
        ...baseSteps(migration),
        `Update version constraint in pubspec.yaml for ${migration.package}`,
        `Run \`flutter pub upgrade ${migration.package}\``,
        `Run \`dart analyze\` and fix all warnings`,
        `Run \`flutter test\` to verify no widget regressions`,
    ];
}
/** swiftpm-specific steps. */
function swiftpmSteps(migration) {
    return [
        ...baseSteps(migration),
        `Update .package(url:, from:) or .upToNextMajor in Package.swift for ${migration.package}`,
        `Run \`swift package update\` to resolve dependencies`,
        `Run \`swift build\` and fix compilation errors`,
        `Run \`swift test\` — fix all failing tests before merging`,
    ];
}
/** Generate ecosystem-appropriate checklist steps. */
function generateSteps(migration) {
    const ecosystem = migration.ecosystem;
    switch (ecosystem) {
        case 'npm':
            return npmSteps(migration);
        case 'pypi':
            return pypiSteps(migration);
        case 'cargo':
            return cargoSteps(migration);
        case 'go':
            return goSteps(migration);
        case 'maven':
            return mavenSteps(migration);
        case 'composer':
            return composerSteps(migration);
        case 'rubygems':
            return rubygemsSteps(migration);
        case 'nuget':
            return nugetSteps(migration);
        case 'pub':
            return pubSteps(migration);
        case 'swiftpm':
            return swiftpmSteps(migration);
    }
}
/** Find direct dependents in catalog that reference the same package. */
function findTransitiveDependents(catalog, migration) {
    // Scan all customPolicies for entries that depend on the same package
    const dependents = [];
    for (const policy of catalog.customPolicies) {
        if (policy.package !== migration.package && policy.ecosystem === migration.ecosystem) {
            // In a real implementation this would parse lock files; for now surface custom policy packages
            // that are in the same ecosystem as potential peers requiring attention.
            dependents.push(`${policy.ecosystem}/${policy.package}`);
        }
    }
    return dependents;
}
/** Generate a full DynamicMigrationPlan for a PendingMigration. */
export function generateMigrationPlan(migration, catalog) {
    return {
        migration,
        steps: generateSteps(migration),
        transitiveDependents: findTransitiveDependents(catalog, migration),
        estimatedEffort: estimateEffort(migration),
    };
}
//# sourceMappingURL=plan-generator.js.map