"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isRawResultRow = exports.isResultValue = void 0;
exports.convertItemTypeToDimensionType = convertItemTypeToDimensionType;
const tslib_1 = require("tslib");
const assertUnreachable_1 = tslib_1.__importDefault(require("../utils/assertUnreachable"));
const item_1 = require("../utils/item");
const field_1 = require("./field");
const isResultValue = (value) => typeof value === 'object' &&
    value !== null &&
    'value' in value &&
    typeof value.value === 'object' &&
    value.value !== null &&
    'raw' in value.value &&
    'formatted' in value.value;
exports.isResultValue = isResultValue;
function convertItemTypeToDimensionType(item) {
    const type = (0, item_1.getItemType)(item);
    switch (type) {
        case field_1.DimensionType.STRING:
        case field_1.MetricType.STRING:
        case field_1.TableCalculationType.STRING:
            return field_1.DimensionType.STRING;
        case field_1.DimensionType.NUMBER:
        case field_1.MetricType.NUMBER:
        case field_1.MetricType.PERCENTILE:
        case field_1.MetricType.MEDIAN:
        case field_1.MetricType.AVERAGE:
        case field_1.MetricType.COUNT:
        case field_1.MetricType.COUNT_DISTINCT:
        case field_1.MetricType.SUM:
        case field_1.MetricType.SUM_DISTINCT:
        case field_1.MetricType.AVERAGE_DISTINCT:
        case field_1.MetricType.MIN:
        case field_1.MetricType.MAX:
        case field_1.MetricType.PERCENT_OF_PREVIOUS:
        case field_1.MetricType.PERCENT_OF_TOTAL:
        case field_1.MetricType.RUNNING_TOTAL:
        case field_1.TableCalculationType.NUMBER:
            return field_1.DimensionType.NUMBER;
        case field_1.DimensionType.TIMESTAMP:
        case field_1.MetricType.TIMESTAMP:
        case field_1.TableCalculationType.TIMESTAMP:
            return field_1.DimensionType.TIMESTAMP;
        case field_1.DimensionType.DATE:
        case field_1.MetricType.DATE:
        case field_1.TableCalculationType.DATE:
            return field_1.DimensionType.DATE;
        case field_1.DimensionType.BOOLEAN:
        case field_1.MetricType.BOOLEAN:
        case field_1.TableCalculationType.BOOLEAN:
            return field_1.DimensionType.BOOLEAN;
        default: {
            return (0, assertUnreachable_1.default)(type, `No dimension type found for field type: ${type}`);
        }
    }
}
const isRawResultRow = (value) => typeof value !== 'object' || value === null;
exports.isRawResultRow = isRawResultRow;
//# sourceMappingURL=results.js.map