"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.hasCustomBinDimension = exports.countCustomDimensionsInMetricQuery = exports.getAdditionalMetricLabel = exports.getCustomMetricDimensionId = exports.hasFormatOptions = exports.isAdditionalMetric = void 0;
const field_1 = require("./field");
const isAdditionalMetric = (value) => value?.table &&
    value?.name &&
    !value?.fieldType &&
    !(0, field_1.isCustomDimension)(value);
exports.isAdditionalMetric = isAdditionalMetric;
const hasFormatOptions = (value) => !!value.formatOptions;
exports.hasFormatOptions = hasFormatOptions;
const getCustomMetricDimensionId = (metric) => `${metric.table}_${metric.baseDimensionName}`;
exports.getCustomMetricDimensionId = getCustomMetricDimensionId;
const getAdditionalMetricLabel = (item) => `${(0, field_1.friendlyName)(item.table)} ${item.label}`;
exports.getAdditionalMetricLabel = getAdditionalMetricLabel;
const countCustomDimensionsInMetricQuery = (metricQuery) => ({
    numFixedWidthBinCustomDimensions: metricQuery.customDimensions?.filter((dimension) => (0, field_1.isCustomBinDimension)(dimension) &&
        dimension.binType === field_1.BinType.FIXED_NUMBER).length || 0,
    numFixedBinsBinCustomDimensions: metricQuery.customDimensions?.filter((dimension) => (0, field_1.isCustomBinDimension)(dimension) &&
        dimension.binType === field_1.BinType.FIXED_WIDTH).length || 0,
    numCustomRangeBinCustomDimensions: metricQuery.customDimensions?.filter((dimension) => (0, field_1.isCustomBinDimension)(dimension) &&
        dimension.binType === field_1.BinType.CUSTOM_RANGE).length || 0,
    numCustomSqlDimensions: metricQuery.customDimensions?.filter((dimension) => (0, field_1.isCustomSqlDimension)(dimension)).length || 0,
});
exports.countCustomDimensionsInMetricQuery = countCustomDimensionsInMetricQuery;
const hasCustomBinDimension = (metricQuery) => metricQuery?.customDimensions &&
    metricQuery.customDimensions.some((dimension) => (0, field_1.isCustomBinDimension)(dimension));
exports.hasCustomBinDimension = hasCustomBinDimension;
//# sourceMappingURL=metricQuery.js.map