"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.calculateExploreWarningReport = exports.calculateCompilationReport = void 0;
const explore_1 = require("../types/explore");
const fields_1 = require("../utils/fields");
const calculateCompilationReport = (args) => {
    const exploresWithErrors = [];
    const baseTableNames = [];
    let successfulExploresCount = 0;
    let metricsCount = 0;
    let dimensionsCount = 0;
    args.explores.forEach((explore) => {
        if ((0, explore_1.isExploreError)(explore)) {
            exploresWithErrors.push(explore);
        }
        else {
            successfulExploresCount += 1;
            baseTableNames.push(explore.baseTable);
            const metrics = (0, fields_1.getMetrics)(explore);
            const dimensions = (0, fields_1.getDimensions)(explore);
            metricsCount += metrics.length;
            dimensionsCount += dimensions.length;
        }
    });
    return {
        totalExploresCount: args.explores.length,
        successfulExploresCount,
        errorExploresCount: exploresWithErrors.length,
        metricsCount,
        dimensionsCount,
        exploresWithErrors,
        baseTableNames,
    };
};
exports.calculateCompilationReport = calculateCompilationReport;
const calculateExploreWarningReport = (args) => {
    const exploresWithWarnings = args.explores.flatMap((explore) => {
        if ((0, explore_1.isExploreError)(explore) || !explore.warnings?.length) {
            return [];
        }
        return [
            {
                name: explore.name,
                warnings: explore.warnings,
            },
        ];
    });
    return {
        warningCount: exploresWithWarnings.reduce((count, explore) => count + explore.warnings.length, 0),
        warningExploreCount: exploresWithWarnings.length,
        exploresWithWarnings,
    };
};
exports.calculateExploreWarningReport = calculateExploreWarningReport;
//# sourceMappingURL=compilationReport.js.map