"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.metricQueryTableViz = exports.tableVizConfigSchema = void 0;
const tslib_1 = require("tslib");
const zod_1 = require("zod");
const validators_1 = require("../../validators");
const customMetrics_1 = require("../customMetrics");
const fieldId_1 = require("../fieldId");
const sortField_1 = tslib_1.__importDefault(require("../sortField"));
exports.tableVizConfigSchema = zod_1.z
    .object({
    exploreName: zod_1.z
        .string()
        .describe('The name of the explore containing the metrics and dimensions used for table query'),
    metrics: zod_1.z
        .array((0, fieldId_1.getFieldIdSchema)({ additionalDescription: null }))
        .describe('The field ids of the metrics to be calculated for the table. They will be grouped by the dimensions.'),
    dimensions: zod_1.z
        .array((0, fieldId_1.getFieldIdSchema)({ additionalDescription: null }))
        .describe('The field id for the dimensions to group the metrics by'),
    sorts: zod_1.z
        .array(sortField_1.default)
        .describe('Sort configuration for the query, it can use a combination of metrics and dimensions.'),
    limit: zod_1.z
        .number()
        .nullable()
        .describe('The maximum number of rows in the table.'),
})
    .describe('Configuration file for generating a table from a query with metrics and dimensions');
const metricQueryTableViz = ({ vizConfig, filters, maxLimit, customMetrics, tableCalculations, }) => ({
    exploreName: vizConfig.exploreName,
    metrics: vizConfig.metrics,
    dimensions: vizConfig.dimensions || [],
    sorts: vizConfig.sorts.map((sort) => ({
        ...sort,
        nullsFirst: sort.nullsFirst ?? undefined,
    })),
    limit: (0, validators_1.getValidAiQueryLimit)(vizConfig.limit, maxLimit),
    filters,
    additionalMetrics: (0, customMetrics_1.filterAggregationCustomMetrics)(customMetrics),
    customMetrics: customMetrics ?? null,
    tableCalculations,
});
exports.metricQueryTableViz = metricQueryTableViz;
//# sourceMappingURL=tableViz.js.map