import { convertColumnMetric } from '../types/dbt';
import { DimensionType, MetricType } from '../types/field';
import { isPeriodOverPeriodAdditionalMetric, } from '../types/metricQuery';
export const convertAdditionalMetric = ({ additionalMetric, table, }) => {
    const metric = convertColumnMetric({
        modelName: table.name,
        dimensionSql: additionalMetric.sql,
        name: additionalMetric.name,
        metric: { ...additionalMetric, filters: undefined },
        tableLabel: table.label,
    });
    const popMetadata = isPeriodOverPeriodAdditionalMetric(additionalMetric)
        ? additionalMetric
        : undefined;
    return {
        ...metric,
        ...(additionalMetric.filters && {
            filters: additionalMetric.filters,
        }),
        ...(additionalMetric.formatOptions && {
            formatOptions: additionalMetric.formatOptions,
        }),
        ...(popMetadata ?? {}),
    };
};
/**
 * Get the custom metric types for a given dimension type
 * @param type
 * @returns
 */
export const getCustomMetricType = (type) => {
    switch (type) {
        case DimensionType.STRING:
        case DimensionType.TIMESTAMP:
        case DimensionType.DATE:
            return [
                MetricType.COUNT_DISTINCT,
                MetricType.COUNT,
                MetricType.MIN,
                MetricType.MAX,
            ];
        case DimensionType.NUMBER:
            return [
                MetricType.MIN,
                MetricType.MAX,
                MetricType.SUM,
                MetricType.PERCENTILE,
                MetricType.MEDIAN,
                MetricType.AVERAGE,
                MetricType.COUNT_DISTINCT,
                MetricType.COUNT,
            ];
        case DimensionType.BOOLEAN:
            return [MetricType.COUNT_DISTINCT, MetricType.COUNT];
        default:
            return [];
    }
};
//# sourceMappingURL=additionalMetrics.js.map