"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EmbedJwtSchema = exports.ChartInteractivityOptionsSchema = exports.InteractivityOptionsSchema = exports.ParameterInteractivityOptionsSchema = exports.DashboardFilterInteractivityOptionsSchema = exports.FilterInteractivityValuesSchema = exports.FilterInteractivityValues = void 0;
exports.isDashboardUuidContent = isDashboardUuidContent;
exports.isDashboardSlugContent = isDashboardSlugContent;
exports.isChartContent = isChartContent;
exports.isDashboardContent = isDashboardContent;
exports.getFilterInteractivityValue = getFilterInteractivityValue;
exports.isFilterInteractivityEnabled = isFilterInteractivityEnabled;
exports.isParameterInteractivityEnabled = isParameterInteractivityEnabled;
const tslib_1 = require("tslib");
const zod_1 = require("zod");
const assertUnreachable_1 = tslib_1.__importDefault(require("../../utils/assertUnreachable"));
var FilterInteractivityValues;
(function (FilterInteractivityValues) {
    FilterInteractivityValues["some"] = "some";
    FilterInteractivityValues["all"] = "all";
    FilterInteractivityValues["none"] = "none";
})(FilterInteractivityValues || (exports.FilterInteractivityValues = FilterInteractivityValues = {}));
exports.FilterInteractivityValuesSchema = zod_1.z.enum([
    FilterInteractivityValues.some,
    FilterInteractivityValues.all,
    FilterInteractivityValues.none,
]);
exports.DashboardFilterInteractivityOptionsSchema = zod_1.z.object({
    enabled: zod_1.z.union([zod_1.z.boolean(), exports.FilterInteractivityValuesSchema]),
    // Nullish because we have python clients that serialize None to null
    allowedFilters: zod_1.z.array(zod_1.z.string()).nullish(),
    hidden: zod_1.z.boolean().optional(),
});
exports.ParameterInteractivityOptionsSchema = zod_1.z.object({
    enabled: zod_1.z.boolean(),
});
exports.InteractivityOptionsSchema = zod_1.z.object({
    dashboardFiltersInteractivity: exports.DashboardFilterInteractivityOptionsSchema.optional(),
    parameterInteractivity: exports.ParameterInteractivityOptionsSchema.optional(),
    canExportCsv: zod_1.z.boolean().optional(),
    canExportImages: zod_1.z.boolean().optional(),
    canExportPagePdf: zod_1.z.boolean().optional(),
    canDateZoom: zod_1.z.boolean().optional(),
    canExplore: zod_1.z.boolean().optional(),
    canViewUnderlyingData: zod_1.z.boolean().optional(),
    // Authorizes embed users to view data app tiles on the dashboard.
    // Off by default — without it, data app tiles render as a placeholder.
    // Setting it grants the embed JWT the broader CASL abilities a data app
    // needs (view:DataApp + view:Explore project-wide) so it can mint a
    // preview token and run its arbitrary metric queries. Mirrors the
    // existing canExplore opt-in: an explicit decision to widen the embed's
    // surface beyond pre-built chart queries.
    canViewDataApps: zod_1.z.boolean().optional(),
});
exports.ChartInteractivityOptionsSchema = zod_1.z.object({
    scopes: zod_1.z.array(zod_1.z.string()).optional(),
    canExportCsv: zod_1.z.boolean().optional(),
    canExportImages: zod_1.z.boolean().optional(),
    canViewUnderlyingData: zod_1.z.boolean().optional(),
});
exports.EmbedJwtSchema = zod_1.z
    .object({
    userAttributes: zod_1.z.record(zod_1.z.unknown()).optional(),
    user: zod_1.z
        .object({
        externalId: zod_1.z.string().nullish(),
        email: zod_1.z.string().nullish(),
    })
        .optional(),
    content: zod_1.z.union([
        zod_1.z
            .object({
            type: zod_1.z.literal('dashboard'),
            projectUuid: zod_1.z.string().optional(),
            dashboardUuid: zod_1.z.string(),
            isPreview: zod_1.z.boolean().optional(),
        })
            .merge(exports.InteractivityOptionsSchema),
        zod_1.z
            .object({
            type: zod_1.z.literal('dashboard'),
            projectUuid: zod_1.z.string().optional(),
            dashboardSlug: zod_1.z.string(),
            isPreview: zod_1.z.boolean().optional(),
        })
            .merge(exports.InteractivityOptionsSchema),
        zod_1.z
            .object({
            type: zod_1.z.literal('chart'),
            projectUuid: zod_1.z.string().optional(),
            contentId: zod_1.z.string(),
            isPreview: zod_1.z.boolean().optional(),
        })
            .merge(exports.ChartInteractivityOptionsSchema),
    ]),
    iat: zod_1.z.number().optional(),
    exp: zod_1.z.number(),
})
    .describe('Configuration file for generating a CSV file from a query with metrics and dimensions');
function isDashboardUuidContent(content) {
    return content.type === 'dashboard' && 'dashboardUuid' in content;
}
function isDashboardSlugContent(content) {
    return content.type === 'dashboard' && 'dashboardSlug' in content;
}
function isChartContent(content) {
    return content.type === 'chart';
}
function isDashboardContent(content) {
    return content.type === 'dashboard';
}
// allows for backwards compatibility with old filter interactivity boolean values
function getFilterInteractivityValue(enabled) {
    if (typeof enabled === 'boolean') {
        return enabled
            ? FilterInteractivityValues.all
            : FilterInteractivityValues.none;
    }
    return enabled;
}
function isFilterInteractivityEnabled(filterInteractivityOptions) {
    if (!filterInteractivityOptions)
        return false;
    const filterInteractivityValue = getFilterInteractivityValue(filterInteractivityOptions.enabled);
    switch (filterInteractivityValue) {
        case FilterInteractivityValues.some:
            return (filterInteractivityOptions.allowedFilters &&
                filterInteractivityOptions.allowedFilters.length > 0);
        case FilterInteractivityValues.all:
            return true;
        case FilterInteractivityValues.none:
            return false;
        default:
            return (0, assertUnreachable_1.default)(filterInteractivityValue, `Unknown FilterInteractivityValue ${filterInteractivityValue}`);
    }
}
function isParameterInteractivityEnabled(parameterInteractivityOptions) {
    return parameterInteractivityOptions?.enabled ?? false;
}
//# sourceMappingURL=index.js.map