"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toolTimeSeriesOutputSchema = exports.toolTimeSeriesArgsSchemaTransformed = exports.toolTimeSeriesArgsSchema = exports.TOOL_TIME_SERIES_VIZ_DESCRIPTION = void 0;
const tslib_1 = require("tslib");
const zod_1 = require("zod");
const followUpTools_1 = require("../../followUpTools");
const types_1 = require("../../types");
const customMetrics_1 = require("../customMetrics");
const filters_1 = require("../filters");
const outputMetadata_1 = require("../outputMetadata");
const tableCalcs_1 = require("../tableCalcs/tableCalcs");
const toolSchemaBuilder_1 = require("../toolSchemaBuilder");
const visualizationMetadata_1 = tslib_1.__importDefault(require("../visualizationMetadata"));
const timeSeriesViz_1 = require("../visualizations/timeSeriesViz");
exports.TOOL_TIME_SERIES_VIZ_DESCRIPTION = `Use this tool to generate a Time Series Chart.`;
exports.toolTimeSeriesArgsSchema = (0, toolSchemaBuilder_1.createToolSchema)()
    .extend({
    ...visualizationMetadata_1.default.shape,
    customMetrics: customMetrics_1.customMetricsSchema,
    tableCalculations: tableCalcs_1.tableCalcsSchema,
    vizConfig: timeSeriesViz_1.timeSeriesMetricVizConfigSchema,
    filters: filters_1.filtersSchemaV2
        .nullable()
        .describe('Filters to apply to the query. Filtered fields must exist in the selected explore or should be referenced from the custom metrics.'),
    followUpTools: zod_1.z
        .array(zod_1.z.union([
        zod_1.z.literal(types_1.AiResultType.TABLE_RESULT),
        zod_1.z.literal(types_1.AiResultType.VERTICAL_BAR_RESULT),
    ]))
        .describe(`The actions the User can ask for after the AI has generated the chart`),
})
    .build();
exports.toolTimeSeriesArgsSchemaTransformed = exports.toolTimeSeriesArgsSchema
    .extend({
    // backwards compatibility for old viz configs
    vizConfig: timeSeriesViz_1.timeSeriesMetricVizConfigSchema.extend({
        xAxisLabel: zod_1.z.string().default(''),
        yAxisLabel: zod_1.z.string().default(''),
    }),
    // backwards compatibility for old viz configs without customMetrics
    customMetrics: customMetrics_1.customMetricsSchema.default(null),
    tableCalculations: tableCalcs_1.tableCalcsSchema.default(null),
    followUpTools: zod_1.z.array(zod_1.z.union([
        zod_1.z.literal(types_1.AiResultType.TABLE_RESULT),
        zod_1.z.literal(types_1.AiResultType.VERTICAL_BAR_RESULT),
        zod_1.z.literal(followUpTools_1.LegacyFollowUpTools.GENERATE_TABLE),
        zod_1.z.literal(followUpTools_1.LegacyFollowUpTools.GENERATE_BAR_VIZ),
    ])),
    filters: filters_1.filtersSchemaTransformed,
})
    .transform((data) => ({
    ...data,
    customMetrics: customMetrics_1.customMetricsSchemaTransformed.parse(data.customMetrics),
    followUpTools: (0, followUpTools_1.legacyFollowUpToolsTransform)(data.followUpTools),
}));
exports.toolTimeSeriesOutputSchema = zod_1.z.object({
    result: zod_1.z.string(),
    metadata: outputMetadata_1.baseOutputMetadataSchema,
});
//# sourceMappingURL=toolTimeSeriesArgs.js.map