import { detectFrameworkWithPackageJson, } from "../build/detect/index.js";
export const PROJECT_GENERATION = '3';
const DIRECT_FRAMEWORK_DEPS = {
    hono: 'hono',
};
export function providerForPackageManager(packageManager) {
    return packageManager === 'bun' ? 'bunjs' : 'nodejs';
}
function providerForRuntime(runtime) {
    if (!runtime)
        return undefined;
    return runtime === 'bun' ? 'bunjs' : 'nodejs';
}
function hasDep(pkg, name) {
    return Boolean(pkg.dependencies?.[name] ?? pkg.devDependencies?.[name]);
}
function detectDirectFramework(pkg) {
    for (const [framework, dep] of Object.entries(DIRECT_FRAMEWORK_DEPS)) {
        if (hasDep(pkg, dep))
            return framework;
    }
    return undefined;
}
export async function detectProjectRegistrationMetadata(dir) {
    const metadata = { generation: PROJECT_GENERATION };
    try {
        const { framework, packageJson } = await detectFrameworkWithPackageJson(dir);
        metadata.provider = providerForRuntime(framework?.runtime);
        if (packageJson) {
            metadata.framework = detectDirectFramework(packageJson);
        }
        if (!metadata.framework && framework?.name && framework.name !== 'generic') {
            metadata.framework = framework.name;
        }
    }
    catch {
        // Registration metadata is best-effort for imports; generation still marks v3.
    }
    return metadata;
}
//# sourceMappingURL=registration-metadata.js.map