"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCustomRangeSelectSql = exports.getFixedWidthBinSelectSql = void 0;
const getFixedWidthBinSelectSql = ({ binWidth, baseDimensionSql, warehouseSqlBuilder, }) => {
    const quoteChar = warehouseSqlBuilder.getStringQuoteChar();
    return `${warehouseSqlBuilder.concatString(`FLOOR(${baseDimensionSql} / ${binWidth}) * ${binWidth}`, `${quoteChar} - ${quoteChar}`, `(FLOOR(${baseDimensionSql} / ${binWidth}) + 1) * ${binWidth} - 1`)}`;
};
exports.getFixedWidthBinSelectSql = getFixedWidthBinSelectSql;
const getCustomRangeSelectSql = ({ binRanges, baseDimensionSql, warehouseSqlBuilder, }) => {
    const quoteChar = warehouseSqlBuilder.getStringQuoteChar();
    const binRangeWhens = binRanges.map((range) => {
        if (range.from === undefined) {
            // First range
            return `WHEN ${baseDimensionSql} < ${range.to} THEN ${warehouseSqlBuilder.concatString(`${quoteChar}<${quoteChar}`, `${range.to}`)}`;
        }
        if (range.to === undefined) {
            // Last range
            return `ELSE ${warehouseSqlBuilder.concatString(`${quoteChar}≥${quoteChar}`, `${range.from}`)}`;
        }
        return `WHEN ${baseDimensionSql} >= ${range.from} AND ${baseDimensionSql} < ${range.to} THEN ${warehouseSqlBuilder.concatString(`${range.from}`, "'-'", `${range.to}`)}`;
    });
    // Add a NULL case for when the dimension is NULL, returning null as the value so it get's correctly formated with the symbol ∅
    const rangeWhens = [
        `WHEN ${baseDimensionSql} IS NULL THEN NULL`,
        ...binRangeWhens,
    ];
    return `CASE
            ${rangeWhens.join('\n')}
            END`;
};
exports.getCustomRangeSelectSql = getCustomRangeSelectSql;
//# sourceMappingURL=customDimensions.js.map