/**
 * Respond to a pending agent interaction (AskUserQuestion).
 *
 * POST - Submit user's answers to the pending interaction.
 *        The agent resumes processing after receiving the response.
 *
 * `featureId` is a polymorphic scope key: a feature UUID, "repo-<id>", or "global".
 */
import { NextResponse } from 'next/server';
import { resolve } from '../../../../../../lib/server-container.js';
export const dynamic = 'force-dynamic';
export async function POST(request, { params }) {
    try {
        const { featureId } = await params;
        const body = (await request.json());
        if (!body.answers || typeof body.answers !== 'object') {
            return NextResponse.json({ error: 'answers must be a non-empty object' }, { status: 400 });
        }
        const useCase = resolve('RespondToInteractionUseCase');
        await useCase.execute({
            featureId,
            answers: body.answers,
        });
        return NextResponse.json({ ok: true });
    }
    catch (error) {
        const message = error instanceof Error ? error.message : String(error);
        const status = message.includes('No pending interaction') ? 409 : 500;
        // eslint-disable-next-line no-console
        console.error('[POST /api/interactive/chat/:featureId/respond]', error);
        return NextResponse.json({ error: message }, { status });
    }
}
