"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.preAggregatePostProcessor = void 0;
const tslib_1 = require("tslib");
const attempt_1 = tslib_1.__importDefault(require("lodash/attempt"));
const isError_1 = tslib_1.__importDefault(require("lodash/isError"));
const explore_1 = require("../types/explore");
const definition_1 = require("./definition");
/**
 * Base post-processor that parses pre-aggregate definitions from dbt meta
 * and attaches them to compiled explores. Does NOT generate virtual
 * pre-aggregate explores — that is handled by the EE post-processor
 * which extends this behavior.
 */
const preAggregatePostProcessor = (compiledExplores, { model, meta }) => {
    const parsedPreAggregates = (0, attempt_1.default)(definition_1.parseDbtPreAggregates, meta.pre_aggregates, model.name);
    if ((0, isError_1.default)(parsedPreAggregates)) {
        return compiledExplores.map((explore) => ({
            name: explore.name,
            label: explore.label,
            groupLabel: explore.groupLabel,
            ...(explore.groups && explore.groups.length > 0
                ? { groups: explore.groups }
                : {}),
            errors: [
                {
                    type: explore_1.InlineErrorType.METADATA_PARSE_ERROR,
                    message: parsedPreAggregates.message ||
                        `Could not parse pre-aggregates for model "${model.name}"`,
                },
            ],
        }));
    }
    // Attach parsed defs to explores (no virtual explore generation)
    return compiledExplores.map((explore) => parsedPreAggregates.length > 0
        ? { ...explore, preAggregates: parsedPreAggregates }
        : explore);
};
exports.preAggregatePostProcessor = preAggregatePostProcessor;
//# sourceMappingURL=postProcessor.js.map