"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getWebAiChartConfig = void 0;
const tslib_1 = require("tslib");
const assertUnreachable_1 = tslib_1.__importDefault(require("../../../../utils/assertUnreachable"));
const types_1 = require("../../types");
const utils_1 = require("../../utils");
const getVerticalBarChartConfig_1 = require("./generateBarVizConfigTool/getVerticalBarChartConfig");
const getTableChartConfig_1 = require("./generateTableVizConfigTool/getTableChartConfig");
const getTimeSeriesChartConfig_1 = require("./generateTimeSeriesVizConfigTool/getTimeSeriesChartConfig");
const getRunQueryChartConfig_1 = require("./runQueryTool/getRunQueryChartConfig");
const getWebAiChartConfig = ({ vizConfig, metricQuery, maxQueryLimit, fieldsMap, overrideChartType, }) => {
    const parsedConfig = (0, utils_1.parseVizConfig)(vizConfig, maxQueryLimit);
    if (!parsedConfig) {
        throw new Error('Invalid viz config');
    }
    switch (parsedConfig.type) {
        case types_1.AiResultType.VERTICAL_BAR_RESULT:
            return {
                ...parsedConfig,
                echartsConfig: (0, getVerticalBarChartConfig_1.getVerticalBarChartConfig)(parsedConfig.vizTool.vizConfig, metricQuery, {
                    title: parsedConfig.vizTool.title,
                    description: parsedConfig.vizTool.description,
                }, fieldsMap),
            };
        case types_1.AiResultType.TIME_SERIES_RESULT:
            return {
                ...parsedConfig,
                echartsConfig: (0, getTimeSeriesChartConfig_1.getTimeSeriesChartConfig)(parsedConfig.vizTool.vizConfig, metricQuery, {
                    title: parsedConfig.vizTool.title,
                    description: parsedConfig.vizTool.description,
                }, fieldsMap),
            };
        case types_1.AiResultType.TABLE_RESULT:
            return {
                ...parsedConfig,
                echartsConfig: (0, getTableChartConfig_1.getTableChartConfig)(),
            };
        case types_1.AiResultType.QUERY_RESULT:
            return {
                type: parsedConfig.type,
                vizTool: parsedConfig.vizTool,
                metricQuery: parsedConfig.metricQuery,
                echartsConfig: (0, getRunQueryChartConfig_1.getRunQueryChartConfig)({
                    queryTool: parsedConfig.vizTool,
                    metricQuery,
                    fieldsMap,
                    overrideChartType,
                }),
            };
        default:
            return (0, assertUnreachable_1.default)(parsedConfig, 'Invalid chart type');
    }
};
exports.getWebAiChartConfig = getWebAiChartConfig;
//# sourceMappingURL=getWebAiChartConfig.js.map