"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getReferencedFilterDimensionForPreAggregation = exports.getReferencedMetricForPreAggregation = exports.getReferencedDimensionForPreAggregation = void 0;
const exploreCompiler_1 = require("../../compiler/exploreCompiler");
const referenceLookup_1 = require("../../compiler/referenceLookup");
const getParsedMetricReference = ({ metric, ref, }) => {
    if (ref === 'TABLE') {
        return undefined;
    }
    return (0, exploreCompiler_1.getParsedReference)(ref, metric.table);
};
const getReferencedDimensionForPreAggregation = ({ metric, ref, tables, }) => {
    const parsedReference = getParsedMetricReference({ metric, ref });
    if (!parsedReference) {
        return undefined;
    }
    return (0, referenceLookup_1.getReferencedDimension)(parsedReference.refTable, parsedReference.refName, tables);
};
exports.getReferencedDimensionForPreAggregation = getReferencedDimensionForPreAggregation;
const getReferencedMetricForPreAggregation = ({ metric, ref, tables, }) => {
    const parsedReference = getParsedMetricReference({ metric, ref });
    if (!parsedReference) {
        return undefined;
    }
    return (0, referenceLookup_1.getReferencedMetric)(parsedReference.refTable, parsedReference.refName, tables);
};
exports.getReferencedMetricForPreAggregation = getReferencedMetricForPreAggregation;
const getReferencedFilterDimensionForPreAggregation = ({ metric, fieldRef, tables, }) => {
    const { refTable, refName } = (0, exploreCompiler_1.getParsedReference)(fieldRef, metric.table);
    return (0, referenceLookup_1.getReferencedDimensionCaseInsensitive)(refTable, refName, tables);
};
exports.getReferencedFilterDimensionForPreAggregation = getReferencedFilterDimensionForPreAggregation;
//# sourceMappingURL=referenceLookup.js.map