"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toolDashboardOutputSchema = exports.toolDashboardArgsSchemaTransformed = exports.toolDashboardArgsSchema = exports.TOOL_DASHBOARD_DESCRIPTION = void 0;
const tslib_1 = require("tslib");
const zod_1 = require("zod");
const assertUnreachable_1 = tslib_1.__importDefault(require("../../../../utils/assertUnreachable"));
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 visualizations_1 = require("../visualizations");
const timeSeriesViz_1 = require("../visualizations/timeSeriesViz");
const toolTableVizArgs_1 = require("./toolTableVizArgs");
const toolTimeSeriesArgs_1 = require("./toolTimeSeriesArgs");
const toolVerticalBarArgs_1 = require("./toolVerticalBarArgs");
exports.TOOL_DASHBOARD_DESCRIPTION = `Use this tool to generate multiple visualizations for a dashboard based on a specific theme. Instead of making multiple parallel tool calls for individual visualizations, this tool takes an array of visualization configurations and generates them all at once, ensuring thematic consistency and better performance.

Dashboard Design Philosophy:
Create "summary" or "executive" level dashboards that provide high-level overviews of specific topics (e.g., Support Dashboard, Revenue Performance, Sales Operations). These dashboards should be designed to monitor trends and key metric performance at a glance.

Recommended Dashboard Structure:
1. **Summary Metrics at the Top**: Start with key performance indicators (KPIs) as tables showing overall summary metrics
2. **Time-Series Analysis**: Include time-series charts with appropriate granularities to show how metrics trend over time:
   - Use line charts for smaller granularities (daily, weekly)
   - Use bar charts for more grouped data (monthly, quarterly)
3. **Detailed Breakdowns**: Add tables with more detail and specific line items that have the biggest impact on metrics
   - Show problematic areas that need attention (e.g., longest response times, highest churn segments)
   - Highlight actionable insights and outliers

Usage tips:
- Use this when you need to create 2 or more related visualizations for a dashboard
- Ensure all visualizations follow the same theme and tell a cohesive story
- Each visualization in the array should have a clear title and description
- Mix different visualization types strategically: tables for KPIs → time-series for trends → tables for detailed breakdowns
- Make use of the breakdownByDimension to show more dense visualizations instead of having multiple different charts for the same metric:
    - "metric A over time, broken down by dimension B"
    - "dimension A broken down by dimension B, with Y axis of important metric"
- If some of the visualizations fail to generate, you can still generate the dashboard with the successful visualizations and return a message about the failed visualizations.
`;
// Base visualization schema that all visualizations must have
const baseVisualizationSchema = zod_1.z.object({
    ...visualizationMetadata_1.default.shape,
    customMetrics: customMetrics_1.customMetricsSchema,
    tableCalculations: tableCalcs_1.tableCalcsSchema,
    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.'),
});
const dashboardTableVisualizationSchema = baseVisualizationSchema.extend({
    type: zod_1.z.literal(types_1.AiResultType.TABLE_RESULT),
    vizConfig: visualizations_1.tableVizConfigSchema,
});
const dashboardTimeSeriesVisualizationSchema = baseVisualizationSchema.extend({
    type: zod_1.z.literal(types_1.AiResultType.TIME_SERIES_RESULT),
    vizConfig: timeSeriesViz_1.timeSeriesMetricVizConfigSchema,
});
const dashboardBarVisualizationSchema = baseVisualizationSchema.extend({
    type: zod_1.z.literal(types_1.AiResultType.VERTICAL_BAR_RESULT),
    vizConfig: visualizations_1.verticalBarMetricVizConfigSchema,
});
const dashboardVisualizationSchema = zod_1.z
    .union([
    dashboardTableVisualizationSchema,
    dashboardTimeSeriesVisualizationSchema,
    dashboardBarVisualizationSchema,
])
    // we don't need followUpTools for dashboard charts but for schema compat reasons we add it here
    .transform((viz) => ({ ...viz, followUpTools: [] }));
exports.toolDashboardArgsSchema = (0, toolSchemaBuilder_1.createToolSchema)()
    .extend({
    title: zod_1.z.string().describe('A descriptive title for the dashboard'),
    description: zod_1.z
        .string()
        .describe('A descriptive summary or explanation for the dashboard.'),
    visualizations: zod_1.z
        .array(dashboardVisualizationSchema)
        .min(2)
        .max(15)
        .describe('Array of visualization configurations to generate for this dashboard. Each should contribute to the overall theme.'),
})
    .build();
exports.toolDashboardArgsSchemaTransformed = exports.toolDashboardArgsSchema.transform((data) => ({
    ...data,
    visualizations: data.visualizations.map((vis) => {
        switch (vis.type) {
            case types_1.AiResultType.TABLE_RESULT:
                return toolTableVizArgs_1.toolTableVizArgsSchemaTransformed.parse(vis);
            case types_1.AiResultType.TIME_SERIES_RESULT:
                return toolTimeSeriesArgs_1.toolTimeSeriesArgsSchemaTransformed.parse(vis);
            case types_1.AiResultType.VERTICAL_BAR_RESULT:
                return toolVerticalBarArgs_1.toolVerticalBarArgsSchemaTransformed.parse(vis);
            default:
                return (0, assertUnreachable_1.default)(vis, 'Invalid visualization type');
        }
    }),
}));
exports.toolDashboardOutputSchema = zod_1.z.object({
    result: zod_1.z.string(),
    metadata: outputMetadata_1.baseOutputMetadataSchema,
});
//# sourceMappingURL=toolDashboardArgs.js.map