"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeReservedValues = exports.mergeReservedDefinitions = exports.mergeReservedNames = exports.getShadowedReservedNames = exports.resolveReservedParameterValues = exports.getReservedParameterDefinitions = exports.isReservedParameterName = exports.getReservedParameterNames = exports.RESERVED_PARAMETERS = void 0;
const timeFrames_1 = require("../types/timeFrames");
/** Registry of reserved parameters. Add an entry here to expose a new system value. */
exports.RESERVED_PARAMETERS = {
    date_zoom: {
        label: 'Date zoom',
        description: 'The selected date zoom granularity in lowercase (e.g. "week"). Empty when no date zoom is selected.',
        type: 'string',
        resolve: ({ dateZoom }) => dateZoom?.granularity
            ? (0, timeFrames_1.getGranularityReferenceValue)(dateZoom.granularity)
            : '',
    },
};
const getReservedParameterNames = () => Object.keys(exports.RESERVED_PARAMETERS);
exports.getReservedParameterNames = getReservedParameterNames;
const isReservedParameterName = (name) => name in exports.RESERVED_PARAMETERS;
exports.isReservedParameterName = isReservedParameterName;
/**
 * Reserved parameter definitions in the shared definition shape (without resolvers), for
 * merging into the available-parameter map and rendering in the parameters UI.
 */
const getReservedParameterDefinitions = () => Object.entries(exports.RESERVED_PARAMETERS).reduce((acc, [name, { resolve, ...definition }]) => ({
    ...acc,
    [name]: definition,
}), {});
exports.getReservedParameterDefinitions = getReservedParameterDefinitions;
/**
 * Resolve every reserved parameter to its value for the given query context.
 */
const resolveReservedParameterValues = (context) => Object.entries(exports.RESERVED_PARAMETERS).reduce((acc, [name, { resolve }]) => ({
    ...acc,
    [name]: resolve(context),
}), {});
exports.resolveReservedParameterValues = resolveReservedParameterValues;
/** Reserved names shadowed by a same-named user parameter (used to surface the override). */
const getShadowedReservedNames = (userParameterNames) => {
    const userNames = new Set(userParameterNames);
    return (0, exports.getReservedParameterNames)().filter((name) => userNames.has(name));
};
exports.getShadowedReservedNames = getShadowedReservedNames;
/** Append reserved names not already taken by a user parameter (deduped, user wins). */
const mergeReservedNames = (userParameterNames) => {
    const userNames = new Set(userParameterNames);
    return [
        ...userParameterNames,
        ...(0, exports.getReservedParameterNames)().filter((name) => !userNames.has(name)),
    ];
};
exports.mergeReservedNames = mergeReservedNames;
/**
 * Merge reserved definitions under user definitions; a user definition of the same name
 * wins (shadows the reserved entry).
 */
const mergeReservedDefinitions = (userDefinitions) => ({
    ...(0, exports.getReservedParameterDefinitions)(),
    ...(userDefinitions ?? {}),
});
exports.mergeReservedDefinitions = mergeReservedDefinitions;
/**
 * Merge resolved reserved values under user values; a user value of the same name wins
 * (shadows the reserved value).
 */
const mergeReservedValues = (userValues, reservedValues) => ({
    ...reservedValues,
    ...(userValues ?? {}),
});
exports.mergeReservedValues = mergeReservedValues;
//# sourceMappingURL=reservedParameters.js.map