import { warnIfUsingNextAnalyticsModeForServiceFeature } from '../../app/engine.js';
import { generatedAnswerAnalyticsClient } from '../../features/generated-answer/generated-answer-analytics-actions.js';
import { buildSearchAPIGeneratedAnswer } from '../core/generated-answer/headless-searchapi-generated-answer.js';
import { buildAnswerApiGeneratedAnswer } from '../knowledge/generated-answer/headless-answerapi-generated-answer.js';
/**
 * Creates a `GeneratedAnswer` controller instance.

 * @param engine - The headless engine.
 * @param props - The configurable `GeneratedAnswer` properties.
 * @returns A `GeneratedAnswer` controller instance.
 *
 * @group Controllers
 * @category GeneratedAnswer
 */
export function buildGeneratedAnswer(engine, props = {}) {
    warnIfUsingNextAnalyticsModeForServiceFeature(engine.state.configuration.analytics.analyticsMode);
    const controller = props.answerConfigurationId
        ? buildAnswerApiGeneratedAnswer(engine, generatedAnswerAnalyticsClient, props)
        : buildSearchAPIGeneratedAnswer(engine, generatedAnswerAnalyticsClient, props);
    return {
        ...controller,
        get state() {
            return controller.state;
        },
    };
}
