import { NextResponse } from 'next/server';
import { resolve } from '../../../../../lib/server-container.js';
// NOTE: Do NOT import TOOL_METADATA directly in API routes.
// The module uses import.meta.url + fs.readdirSync to load JSON files,
// which breaks when Turbopack bundles it (import.meta.url resolves to
// the bundled chunk location where the tools/ directory doesn't exist).
// Tool validation is delegated to the use case via the DI container,
// where the module loads correctly in the Node.js CLI bootstrap context.
export async function POST(_request, { params }) {
    const { id } = await params;
    try {
        const useCase = resolve('InstallToolUseCase');
        const status = await useCase.execute(id);
        if (status.status === 'error') {
            return NextResponse.json({ error: status.errorMessage }, { status: 500 });
        }
        return NextResponse.json({ status });
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to install tool';
        return NextResponse.json({ error: message }, { status: 500 });
    }
}
