import { composeFunction } from '../../ssr-engine/common.js';
import { SolutionType } from '../types/common.js';
import { buildFactory, } from './build-factory.js';
export function hydratedRecommendationStaticStateFactory(controllerDefinitions, options) {
    return composeFunction(async (...params) => {
        const solutionTypeBuild = await buildFactory(controllerDefinitions, options)(SolutionType.recommendation);
        const buildResult = (await solutionTypeBuild(...params));
        const staticState = await hydratedRecommendationStaticStateFactory(controllerDefinitions, options).fromBuildResult({
            buildResult,
            searchActions: params[0].searchActions,
        });
        return staticState;
    }, {
        fromBuildResult: async (...params) => {
            const [{ buildResult: { engine, controllers }, searchActions, },] = params;
            searchActions.forEach((action) => {
                engine.dispatch(action);
            });
            await engine.waitForRequestCompletedAction();
            return { engine, controllers };
        },
    });
}
