"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SearchItemType = exports.getSearchResultId = exports.isDashboardSearchResult = exports.isSqlChartSearchResult = exports.isSavedChartSearchResult = exports.isTableErrorSearchResult = exports.isFieldSearchResult = exports.isExploreSearchResult = void 0;
exports.getSearchItemTypeFromResultKey = getSearchItemTypeFromResultKey;
const tslib_1 = require("tslib");
const assertUnreachable_1 = tslib_1.__importDefault(require("../utils/assertUnreachable"));
const isExploreSearchResult = (value) => 'explore' in value;
exports.isExploreSearchResult = isExploreSearchResult;
const isFieldSearchResult = (value) => 'table' in value;
exports.isFieldSearchResult = isFieldSearchResult;
const isTableErrorSearchResult = (value) => 'explore' in value && 'validationErrors' in value;
exports.isTableErrorSearchResult = isTableErrorSearchResult;
const isSavedChartSearchResult = (value) => 'chartSource' in value && value.chartSource === 'saved';
exports.isSavedChartSearchResult = isSavedChartSearchResult;
const isSqlChartSearchResult = (value) => 'chartSource' in value && value.chartSource === 'sql';
exports.isSqlChartSearchResult = isSqlChartSearchResult;
const isDashboardSearchResult = (value) => 'charts' in value;
exports.isDashboardSearchResult = isDashboardSearchResult;
const getSearchResultId = (meta) => {
    if (!meta || (0, exports.isTableErrorSearchResult)(meta)) {
        return '';
    }
    if ((0, exports.isExploreSearchResult)(meta)) {
        if ((0, exports.isFieldSearchResult)(meta)) {
            return `${meta.explore}.${meta.table}.${meta.name}`;
        }
        return `${meta.explore}.${meta.name}`;
    }
    return meta.uuid;
};
exports.getSearchResultId = getSearchResultId;
var SearchItemType;
(function (SearchItemType) {
    SearchItemType["DASHBOARD"] = "dashboard";
    SearchItemType["DASHBOARD_TAB"] = "dashboard_tab";
    SearchItemType["CHART"] = "saved_chart";
    SearchItemType["SQL_CHART"] = "sql_chart";
    SearchItemType["SPACE"] = "space";
    SearchItemType["TABLE"] = "table";
    SearchItemType["FIELD"] = "field";
    SearchItemType["PAGE"] = "page";
    SearchItemType["DATA_APP"] = "data_app";
    SearchItemType["SETTINGS"] = "settings";
})(SearchItemType || (exports.SearchItemType = SearchItemType = {}));
function getSearchItemTypeFromResultKey(searchResultKey) {
    switch (searchResultKey) {
        case 'spaces':
            return SearchItemType.SPACE;
        case 'dashboards':
            return SearchItemType.DASHBOARD;
        case 'savedCharts':
            return SearchItemType.CHART;
        case 'tables':
            return SearchItemType.TABLE;
        case 'fields':
            return SearchItemType.FIELD;
        case 'pages':
            return SearchItemType.PAGE;
        case 'sqlCharts':
            return SearchItemType.SQL_CHART;
        case 'dashboardTabs':
            return SearchItemType.DASHBOARD_TAB;
        case 'dataApps':
            return SearchItemType.DATA_APP;
        default:
            return (0, assertUnreachable_1.default)(searchResultKey, `unexpected search result key: ${searchResultKey}`);
    }
}
//# sourceMappingURL=search.js.map