"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCategoriesFromResource = exports.getSpotlightConfigurationForResource = void 0;
const errors_1 = require("../types/errors");
/**
 * Get the spotlight configuration for a resource
 */
const getSpotlightConfigurationForResource = ({ visibility, categories, filterBy, segmentBy, owner, }) => {
    if (visibility === undefined) {
        return {};
    }
    return {
        spotlight: {
            visibility,
            categories,
            ...(filterBy ? { filterBy } : {}),
            ...(segmentBy ? { segmentBy } : {}),
            ...(owner ? { owner } : {}),
        },
    };
};
exports.getSpotlightConfigurationForResource = getSpotlightConfigurationForResource;
/**
 * Get the categories from the resource and validate them against the project config
 * @param resourceType - The type of the resource
 * @param resourceName - The name of the resource
 * @param spotlightConfig - The spotlight config
 * @param resourceCategories - The categories from the resource
 * @returns The categories from the resource
 */
const getCategoriesFromResource = (resourceType, resourceName, spotlightConfig, resourceCategories = []) => {
    // Get all valid category references from the global spotlight config
    const categoriesDefinedInProjectConfig = Object.keys(spotlightConfig?.categories || {}) || [];
    // Check if any metric categories aren't defined in the global config
    const invalidCategories = resourceCategories.filter((category) => !categoriesDefinedInProjectConfig.includes(category));
    if (invalidCategories.length > 0) {
        throw new errors_1.ParseError(`Invalid spotlight categories found in ${resourceType} '${resourceName}': ${invalidCategories.join(', ')}. Categories must be defined in project config.`);
    }
    return resourceCategories;
};
exports.getCategoriesFromResource = getCategoriesFromResource;
//# sourceMappingURL=lightdashProjectConfig.js.map