import { filterObject } from '../../../utils/utils.js';
import { createStaticState } from '../controller-utils.js';
import { SolutionType } from '../types/controller-constants.js';
import { filterRecommendationControllers } from '../utils/recommendation-filter.js';
import { buildFactory, } from './build-factory.js';
export function fetchRecommendationStaticStateFactory(controllerDefinitions, options) {
    const getAllowedRecommendationKeys = (props) => {
        if (props && 'controllers' in props) {
            const enabledRecommendationControllers = filterObject(props.controllers, (value) => Boolean(value.enabled));
            return Object.keys(enabledRecommendationControllers);
        }
        return [];
    };
    return async (...params) => {
        const [props] = params;
        const allowedRecommendationKeys = getAllowedRecommendationKeys(props);
        const solutionTypeBuild = await buildFactory(controllerDefinitions, options)(SolutionType.recommendation);
        const { engine, controllers } = (await solutionTypeBuild(...params));
        filterRecommendationControllers(controllers, controllerDefinitions ?? {}).refresh(allowedRecommendationKeys);
        const searchActions = await Promise.all(engine.waitForRequestCompletedAction());
        return createStaticState({
            searchActions,
            controllers,
        });
    };
}
