"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mcpRenderChartStructuredOutputSchema = exports.mcpGetQueryResultStructuredOutputSchema = exports.mcpRunMetricQueryStructuredOutputSchema = exports.mcpRunSqlStructuredOutputSchema = exports.createMcpAsyncQueryRunStructuredOutputSchema = exports.createMcpStructuredOutputSchema = exports.mcpQueryResultTerminalResultSchema = exports.mcpQueryResultDoneMetricQueryResultSchema = exports.mcpQueryResultDoneSqlResultSchema = exports.mcpRenderChartResultSchema = exports.mcpMetricQueryCompletedResultSchema = exports.mcpMetricQueryResultRowsFieldsSchema = exports.mcpSqlQueryCompletedResultSchema = exports.mcpSqlQueryRowsColumnsSchema = exports.mcpRunningQueryResultSchema = exports.mcpHeartbeatAtSchema = exports.mcpNextPollAfterMsSchema = exports.mcpAsyncQueryUuidSchema = void 0;
const zod_1 = require("zod");
const createMcpAsyncQueryUuidSchema = () => zod_1.z.string().uuid();
exports.mcpAsyncQueryUuidSchema = createMcpAsyncQueryUuidSchema();
exports.mcpNextPollAfterMsSchema = zod_1.z.number().int().positive();
exports.mcpHeartbeatAtSchema = zod_1.z
    .string()
    .describe('ISO timestamp for when Lightdash last checked this async query and confirmed it is still running.');
exports.mcpRunningQueryResultSchema = zod_1.z.object({
    status: zod_1.z
        .literal('running')
        .describe('Present when the query is still running and should be polled with get_query_result.'),
    queryUuid: exports.mcpAsyncQueryUuidSchema.describe('Async query UUID to pass to get_query_result when status is running.'),
    nextPollAfterMs: exports.mcpNextPollAfterMsSchema.describe('Suggested delay before polling get_query_result for this query.'),
    heartbeatAt: exports.mcpHeartbeatAtSchema,
});
exports.mcpSqlQueryRowsColumnsSchema = zod_1.z.object({
    rows: zod_1.z
        .array(zod_1.z.record(zod_1.z.unknown()))
        .describe('Result rows. Each row is an object keyed by column name. Values come from the warehouse as JSON-serializable primitives (numbers, strings, booleans, ISO date strings, or null).'),
    columns: zod_1.z
        .array(zod_1.z.string())
        .describe('Ordered list of column names matching the keys in each row of `rows`.'),
    rowCount: zod_1.z
        .number()
        .int()
        .nonnegative()
        .describe('Total number of rows returned. May be less than the requested limit.'),
});
exports.mcpSqlQueryCompletedResultSchema = exports.mcpSqlQueryRowsColumnsSchema.extend({
    status: zod_1.z.literal('done'),
    sqlRunnerUrl: zod_1.z.string().nullable(),
});
exports.mcpMetricQueryResultRowsFieldsSchema = zod_1.z.object({
    rows: zod_1.z.array(zod_1.z.record(zod_1.z.unknown())),
    fields: zod_1.z.record(zod_1.z.unknown()),
});
exports.mcpMetricQueryCompletedResultSchema = exports.mcpMetricQueryResultRowsFieldsSchema.extend({
    status: zod_1.z.literal('done'),
    queryUuid: createMcpAsyncQueryUuidSchema(),
    exploreUrl: zod_1.z.string().nullable(),
});
exports.mcpRenderChartResultSchema = zod_1.z
    .object({
    status: zod_1.z.literal('done'),
    queryUuid: createMcpAsyncQueryUuidSchema(),
    exploreUrl: zod_1.z.string().nullable(),
    echartsOption: zod_1.z.unknown().nullable(),
})
    .describe('Rendered chart result for a completed query.');
exports.mcpQueryResultDoneSqlResultSchema = zod_1.z.object({
    status: zod_1.z.literal('done'),
    queryUuid: createMcpAsyncQueryUuidSchema(),
    sqlRunnerUrl: zod_1.z.string().nullable(),
    ...exports.mcpSqlQueryRowsColumnsSchema.shape,
});
exports.mcpQueryResultDoneMetricQueryResultSchema = zod_1.z.object({
    status: zod_1.z.literal('done'),
    queryUuid: createMcpAsyncQueryUuidSchema(),
    exploreUrl: zod_1.z.string().nullable(),
    ...exports.mcpMetricQueryResultRowsFieldsSchema.shape,
});
exports.mcpQueryResultTerminalResultSchema = zod_1.z.object({
    status: zod_1.z.enum(['error', 'cancelled', 'expired']),
    queryUuid: createMcpAsyncQueryUuidSchema(),
    error: zod_1.z.string().nullable(),
});
const createMcpStructuredOutputSchema = (result) => zod_1.z.object({
    result,
});
exports.createMcpStructuredOutputSchema = createMcpStructuredOutputSchema;
const createMcpAsyncQueryRunStructuredOutputSchema = (completedResult) => (0, exports.createMcpStructuredOutputSchema)(zod_1.z.union([completedResult, exports.mcpRunningQueryResultSchema]));
exports.createMcpAsyncQueryRunStructuredOutputSchema = createMcpAsyncQueryRunStructuredOutputSchema;
exports.mcpRunSqlStructuredOutputSchema = (0, exports.createMcpAsyncQueryRunStructuredOutputSchema)(exports.mcpSqlQueryCompletedResultSchema);
exports.mcpRunMetricQueryStructuredOutputSchema = (0, exports.createMcpAsyncQueryRunStructuredOutputSchema)(exports.mcpMetricQueryCompletedResultSchema);
exports.mcpGetQueryResultStructuredOutputSchema = (0, exports.createMcpStructuredOutputSchema)(zod_1.z.union([
    exports.mcpRunningQueryResultSchema,
    exports.mcpQueryResultDoneSqlResultSchema,
    exports.mcpQueryResultDoneMetricQueryResultSchema,
    exports.mcpQueryResultTerminalResultSchema,
]));
exports.mcpRenderChartStructuredOutputSchema = (0, exports.createMcpStructuredOutputSchema)(exports.mcpRenderChartResultSchema);
//# sourceMappingURL=toolQueryResultSchemas.js.map