import { getItemId } from '../../utils/item';
export const getDimensionBaseName = (dimension) => dimension.timeIntervalBaseDimensionName ?? dimension.name;
export const getDimensionReferences = ({ dimension, baseTable, }) => {
    const baseName = getDimensionBaseName(dimension);
    const tableQualifiedReference = `${dimension.table}.${baseName}`;
    if (dimension.table === baseTable) {
        return [baseName, tableQualifiedReference];
    }
    return [tableQualifiedReference];
};
export const getMetricReferences = ({ metric, baseTable, }) => {
    const references = [`${metric.table}.${metric.name}`];
    if (metric.table === baseTable) {
        references.push(metric.name);
    }
    return references;
};
export const getMetricsByReference = ({ tables, baseTable, }) => Object.values(tables).reduce((acc, table) => {
    Object.values(table.metrics).forEach((metric) => {
        const fieldId = getItemId(metric);
        new Set([
            fieldId,
            ...getMetricReferences({
                metric,
                baseTable,
            }),
        ]).forEach((reference) => {
            acc.set(reference, { fieldId, metric });
        });
    });
    return acc;
}, new Map());
//# sourceMappingURL=references.js.map