// (C) 2021-2026 GoodData Corporation
import { insightFilters, insightMeasures, isAttributeFilter, isDateFilter, isMeasureValueFilter, isRankingFilter, } from "@gooddata/sdk-model";
import { getSourceMeasureFiltersForDrillDefinition, isMatchingSourceInsightFilter, } from "../../../../_staging/drills/drillingUtils.js";
export function getIncludedSourceInsightFilters(sourceInsight, includedSourceInsightFiltersObjRefs) {
    const sourceFilters = sourceInsight
        ? insightFilters(sourceInsight).filter((filter) => isAttributeFilter(filter) ||
            isDateFilter(filter) ||
            isMeasureValueFilter(filter) ||
            isRankingFilter(filter))
        : [];
    return includedSourceFilters(sourceFilters, includedSourceInsightFiltersObjRefs);
}
export function getIncludedSourceMeasureFilters(sourceInsight, drillDefinition) {
    if (!sourceInsight) {
        return [];
    }
    const sourceMeasureFilters = getSourceMeasureFiltersForDrillDefinition(drillDefinition, insightMeasures(sourceInsight));
    return includedSourceFilters(sourceMeasureFilters, drillDefinition.includedSourceMeasureFiltersObjRefs ?? []);
}
export function getIncludedSourceFiltersForDashboard(sourceInsight, drillDefinition) {
    const sourceMeasureFilters = getIncludedSourceMeasureFilters(sourceInsight, drillDefinition);
    const sourceInsightFilters = getIncludedSourceInsightFilters(sourceInsight, drillDefinition.includedSourceInsightFiltersObjRefs ?? []).filter((filter) => {
        return isAttributeFilter(filter) || isDateFilter(filter);
    });
    // Keep the same precedence as drill-to-insight: measure filters win over source insight filters.
    return [...sourceMeasureFilters, ...sourceInsightFilters];
}
function includedSourceFilters(sourceFilters, includedFilterObjRefs) {
    return sourceFilters.filter((sourceFilter) => {
        return includedFilterObjRefs.some((includedFilterObjRef) => isMatchingSourceInsightFilter(sourceFilter, includedFilterObjRef));
    });
}
//# sourceMappingURL=sourceDrillFilters.js.map