// (C) 2026 GoodData Corporation
import { isNumberParameterDefinition, objRefToString, } from "@gooddata/sdk-model";
/**
 * Builds the parameter slice entries from the dashboard's persisted parameters and the
 * workspace parameter catalog.
 *
 * - When the persisted entry has an explicit `value`, use it as `runtimeOverride`.
 * - Otherwise, look up the workspace default.
 * - When neither is available (catalog gated off / failed / ref missing), `runtimeOverride`
 *   stays `undefined` so the backend keeps using the parameter's own default at execution time.
 */
export function hydrateParameterEntries(dashboardParameters, workspaceParameters) {
    if (!dashboardParameters || dashboardParameters.length === 0) {
        return [];
    }
    const workspaceByRef = new Map(workspaceParameters.map((wp) => [objRefToString(wp.ref), wp]));
    return dashboardParameters.map((parameter) => {
        if (parameter.value !== undefined) {
            return { parameter, runtimeOverride: parameter.value };
        }
        const workspaceParameter = workspaceByRef.get(objRefToString(parameter.ref));
        const workspaceDefault = workspaceParameter && isNumberParameterDefinition(workspaceParameter.definition)
            ? workspaceParameter.definition.defaultValue
            : undefined;
        return { parameter, runtimeOverride: workspaceDefault };
    });
}
//# sourceMappingURL=parameterHydration.js.map