// (C) 2021-2026 GoodData Corporation
import { absoluteDateFilterValues, filterAttributeElements, filterLocalIdentifier, filterObjRef, isAllTimeDateFilter, isArbitraryAttributeFilter, isAttributeFilterWithSelection, isMatchAttributeFilter, isPositiveAttributeFilter, isRelativeBoundedDateFilter, isRelativeDateFilter, relativeDateFilterValues, } from "@gooddata/sdk-model";
/**
 * Creates the ChangeDateFilterSelection command.
 *
 * @remarks
 * Dispatching this command will result in change of dashboard's date filter, or error in case of invalid
 * update (e.g. hidden date filter option by dateFilterConfig).
 *
 * @param type - date filter type; absolute filters use exact start and end dates, while relative filters use offsets from today
 * @param granularity - granularity on which the filter works; days, weeks, months, quarters or years.
 * @param from - start date; if not specified, then the start date will be unbounded
 * @param to - end date; if not specified, then the end date will be unbounded
 * @param dateFilterOptionLocalId - localId of the {@link @gooddata/sdk-backend-spi#IDateFilterOption} selected
 * @param localIdentifier - localId of the date filter
 * @param correlationId - specify correlation id to use for this command. this will be included in all
 *  events that will be emitted during the command processing
 * @param dataSet -
 * @param isWorkingSelectionChange -
 * @param boundedFilter -
 * @see {@link ChangeDateFilterSelection} for a more complete description of the different parameters
 *
 * @public
 */
export function changeDateFilterSelection(type, granularity, from, to, dateFilterOptionLocalId, correlationId, dataSet, isWorkingSelectionChange, localIdentifier, boundedFilter, emptyValueHandling) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.DATE_FILTER.CHANGE_SELECTION",
        correlationId,
        payload: {
            dataSet,
            type,
            granularity,
            from,
            to,
            dateFilterOptionLocalId,
            isWorkingSelectionChange,
            localIdentifier,
            boundedFilter,
            emptyValueHandling,
        },
    };
}
/**
 * Creates the ChangeDateFilterSelection command.
 *
 * @remarks
 * Dispatching this command will result in change of dashboard's date filter, or error in case of invalid
 * update (e.g. hidden date filter option by dateFilterConfig).
 *
 * All parameters for {@link ChangeDateFilterSelection} command is derived from the provided date filter.
 *
 * See {@link ChangeDateFilterSelection} for a more complete description of the different parameters
 *
 * @param filter - date filter to apply
 * @param correlationId - specify correlation id to use for this command. this will be included in all
 *  events that will be emitted during the command processing
 *
 * @public
 */
export function applyDateFilter(filter, correlationId) {
    if (isAllTimeDateFilter(filter)) {
        const values = relativeDateFilterValues(filter, true);
        const emptyValueHandling = filter.relativeDateFilter.emptyValueHandling;
        if (emptyValueHandling === undefined) {
            return clearDateFilterSelection(correlationId, values.dataSet);
        }
        // All time with explicit empty values handling needs to be persisted on the dashboard,
        // so it must not be converted to a "clear date filter" command.
        return changeDateFilterSelection("relative", "GDC.time.date", undefined, undefined, undefined, correlationId, values.dataSet, undefined, filter.relativeDateFilter.localIdentifier, undefined, emptyValueHandling);
    }
    if (isRelativeDateFilter(filter)) {
        const values = relativeDateFilterValues(filter, true);
        const boundedFilter = isRelativeBoundedDateFilter(filter)
            ? filter.relativeDateFilter.boundedFilter
            : undefined;
        const emptyValueHandling = filter.relativeDateFilter.emptyValueHandling;
        return changeDateFilterSelection("relative", values.granularity, values.from, values.to, undefined, correlationId, values.dataSet, undefined, filter.relativeDateFilter.localIdentifier, boundedFilter, emptyValueHandling);
    }
    else {
        const values = absoluteDateFilterValues(filter, true);
        const emptyValueHandling = filter.absoluteDateFilter.emptyValueHandling;
        return changeDateFilterSelection("absolute", "GDC.time.date", values.from, values.to, undefined, correlationId, values.dataSet, undefined, filter.absoluteDateFilter.localIdentifier, undefined, emptyValueHandling);
    }
}
/**
 * This convenience function will create ChangeDateFilterSelection configured so that the date filter will be
 * unbounded - showing data for 'All Time'.
 *
 * @param correlationId - specify correlation id to use for this command. this will be included in all
 *  events that will be emitted during the command processing
 * @param dataSet -
 * @param isWorkingSelectionChange -
 * @param localIdentifier -
 *
 * @public
 */
export function clearDateFilterSelection(correlationId, dataSet, isWorkingSelectionChange, localIdentifier, emptyValueHandling) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.DATE_FILTER.CHANGE_SELECTION",
        correlationId,
        payload: {
            dataSet,
            type: "relative",
            granularity: "GDC.time.date",
            isWorkingSelectionChange,
            localIdentifier,
            emptyValueHandling,
        },
    };
}
/**
 * Creates the AddAttributeFilter command. Dispatching this command will result in the addition
 * of another attribute filter to the dashboard's filter bar, at desired position,
 * or error in case of invalid update (e.g. wrong or duplicated displayForm)
 *
 * The filter will be set for the display form provided by reference. When created, the filter will be
 * no-op - all the elements will be selected.
 * @remarks Does not support adding text filters.
 *
 * @param displayForm - specify attribute display form which will be used for filtering
 * @param index - specify index among the attribute filters at which the new filter should be placed.
 *  The index starts at zero and there is convenience that index of -1 would add the filter at the end.
 * @param correlationId - specify correlation id to use for this command. this will be included in all
 *  events that will be emitted during the command processing.
 * @param selectionMode - single or multi value selection mode of the filter.
 * @param mode - specify the visibility mode of attribute filter
 * @param initialSelection - specify the initial selection of attribute elements
 * @param initialIsNegativeSelection - specify if the initial selection of attribute elements is a negative one
 * @param localIdentifier - local identifier
 * @param primaryDisplayForm - specify the primary display form of attribute filter
 * @param title - specify custom title of attribute filter
 * @beta
 */
export function addAttributeFilter(displayForm, index, correlationId, selectionMode, mode, initialSelection, initialIsNegativeSelection, localIdentifier, primaryDisplayForm, title) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.ATTRIBUTE_FILTER.ADD",
        correlationId,
        payload: {
            displayForm,
            primaryDisplayForm,
            index,
            selectionMode,
            mode,
            initialSelection,
            initialIsNegativeSelection,
            localIdentifier,
            title,
        },
    };
}
/**
 * Creates the AddTextAttributeFilter command. Dispatching this command will result in the addition
 * of a text attribute filter (arbitrary or match) to the dashboard's filter bar, at desired position,
 * or error in case of invalid update (e.g. wrong or duplicated displayForm).
 *
 * @param filter - the text attribute filter to add (IDashboardArbitraryAttributeFilter or IDashboardMatchAttributeFilter)
 * @param index - specify index among the attribute filters at which the new filter should be placed.
 *  The index starts at zero and there is convenience that index of -1 would add the filter at the end.
 * @param correlationId - specify correlation id to use for this command
 * @param mode - specify the visibility mode of attribute filter
 * @beta
 */
export function addTextAttributeFilter(filter, index, correlationId, mode) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.TEXT_ATTRIBUTE_FILTER.ADD",
        correlationId,
        payload: {
            filter,
            index,
            mode,
        },
    };
}
/**
 * Creates the RemoveAttributeFilters command. Dispatching this command will result in the removal
 * of dashboard's attribute filter with the provided local identifier.
 *
 * @param filterLocalId - dashboard attribute filter's local identifier
 * @param correlationId - specify correlation id to use for this command. this will be included in all
 *  events that will be emitted during the command processing
 * @beta
 */
export function removeAttributeFilter(filterLocalId, correlationId) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.ATTRIBUTE_FILTER.REMOVE",
        correlationId,
        payload: {
            filterLocalIds: [filterLocalId],
        },
    };
}
/**
 * Creates the RemoveAttributeFilters command. Dispatching this command will result in the removal
 * of dashboard's attribute filters with the provided local identifiers.
 *
 * @param filterLocalIds - an array of dashboard attribute filter's local identifiers
 * @param correlationId - specify correlation id to use for this command. this will be included in all
 *  events that will be emitted during the command processing
 * @beta
 */
export function removeAttributeFilters(filterLocalIds, correlationId) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.ATTRIBUTE_FILTER.REMOVE",
        correlationId,
        payload: {
            filterLocalIds,
        },
    };
}
/**
 * Creates the MoveAttributeFilter command. Dispatching this command will result in move of the dashboard attribute
 * filter with the provided local id to a new spot. The new spot is defined by index. For convenience the index
 * of -1 means move to the end of the attribute filter list.
 *
 * @param filterLocalId - dashboard filter's local identifier
 * @param index - specify index among the attribute filters at which the new filter should be placed.
 *  The index starts at zero and there is convenience that index of -1 would add the filter at the end.
 * @param correlationId - specify correlation id to use for this command. this will be included in all
 *  events that will be emitted during the command processing
 *
 * @beta
 */
export function moveAttributeFilter(filterLocalId, index, correlationId) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.ATTRIBUTE_FILTER.MOVE",
        correlationId,
        payload: {
            filterLocalId,
            index,
        },
    };
}
/**
 * Creates the ChangeAttributeFilterSelection command for applied filters.
 *
 * @remarks
 * Dispatching this command will result in application of element selection for the dashboard attribute filter
 * with the provided id, or error in case of invalid update (e.g. non-existing filterLocalId).
 *
 * The attribute elements can be provided either using their URI (primary key) or value. Together with the
 * elements you must indicate the selection type - either 'IN' or 'NOT_IN'.
 *
 * If you want to change working filters use {@link changeWorkingAttributeFilterSelection}.
 * See {@link ChangeAttributeFilterSelectionPayload.isWorkingSelectionChange} for details.
 *
 * @remarks see {@link resetAttributeFilterSelection} for convenience function to select all attribute elements of
 *  particular filter.
 *
 * See also {@link applyAttributeFilter} for convenient function when you have an {@link @gooddata/sdk-model#IAttributeFilter} instance.
 *
 *  @example
 * ```
 * const selectionType = isPositiveAttributeFilter ? "IN" : "NOT_IN";
 * ```
 *
 * To create this command without a need to calculate the payload values from a {@link @gooddata/sdk-model#IFilter} object,
 * we recommend to use {@link applyAttributeFilter} command creator instead.
 *
 * @param filterLocalId - dashboard attribute filter's local id
 * @param elements - elements
 * @param selectionType - selection type. either 'IN' or 'NOT_IN'
 * @param correlationId - specify correlation id to use for this command. this will be included in all
 *  events that will be emitted during the command processing
 * @param isSelectionInvalid -
 *
 * @public
 */
export function changeAttributeFilterSelection(filterLocalId, elements, selectionType, correlationId, isSelectionInvalid) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.ATTRIBUTE_FILTER.CHANGE_SELECTION",
        correlationId,
        payload: {
            filterLocalId,
            elements,
            selectionType,
            isSelectionInvalid,
        },
    };
}
/**
 * Creates the ChangeAttributeFilterSelection command for adhoc migrated attribute filter.
 *
 * @remarks
 * Dispatching this command will result in application of element selection for the dashboard attribute filter
 * with the provided id, or error in case of invalid update (e.g. non-existing filterLocalId).
 *
 * The attribute elements can be provided either using their URI (primary key) or value. Together with the
 * elements you must indicate the selection type - either 'IN' or 'NOT_IN'.
 *
 * @remarks see {@link resetAttributeFilterSelection} for convenience function to select all attribute elements of
 *  particular filter.
 *
 * See also {@link applyAttributeFilter} for convenient function when you have an {@link @gooddata/sdk-model#IAttributeFilter} instance.
 *
 *  @example
 * ```
 * const selectionType = isPositiveAttributeFilter ? "IN" : "NOT_IN";
 * ```
 *
 * To create this command without a need to calculate the payload values from a {@link @gooddata/sdk-model#IFilter} object,
 * we recommend to use {@link applyAttributeFilter} command creator instead.
 *
 * @param filterLocalId - dashboard attribute filter's local id
 * @param elements - elements
 * @param selectionType - selection type. either 'IN' or 'NOT_IN'
 * @param correlationId - specify correlation id to use for this command. this will be included in all
 *  events that will be emitted during the command processing
 *
 * @internal
 */
export function changeMigratedAttributeFilterSelection(filterLocalId, elements, selectionType, correlationId) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.ATTRIBUTE_FILTER.CHANGE_SELECTION",
        correlationId,
        payload: {
            filterLocalId,
            elements,
            selectionType,
            isResultOfMigration: true,
        },
    };
}
/**
 * Creates the ChangeAttributeFilterSelection command for working filter.
 *
 * @remarks
 * Dispatching this command will result in changing working element selection for the dashboard attribute filter
 * with the provided id, or error in case of invalid update (e.g. non-existing filterLocalId).
 *
 * The attribute elements can be provided either using their URI (primary key) or value. Together with the
 * elements you must indicate the selection type - either 'IN' or 'NOT_IN'.
 *
 * If you want to change applied filters use {@link changeAttributeFilterSelection}.
 * See {@link ChangeAttributeFilterSelectionPayload.isWorkingSelectionChange} for details.
 *
 * @remarks see {@link resetAttributeFilterSelection} for convenience function to select all attribute elements of
 *  particular filter.
 *
 * See also {@link applyAttributeFilter} for convenient function when you have an {@link @gooddata/sdk-model#IAttributeFilter} instance.
 *
 *  @example
 * ```
 * const selectionType = isPositiveAttributeFilter ? "IN" : "NOT_IN";
 * ```
 *
 * To create this command without a need to calculate the payload values from a {@link @gooddata/sdk-model#IFilter} object,
 * we recommend to use {@link applyAttributeFilter} command creator instead.
 *
 * @param filterLocalId - dashboard attribute filter's local id
 * @param elements - elements
 * @param selectionType - selection type. either 'IN' or 'NOT_IN'
 * @param correlationId - specify correlation id to use for this command. this will be included in all
 *  events that will be emitted during the command processing
 * @param isSelectionInvalid -
 *
 * @public
 */
export function changeWorkingAttributeFilterSelection(filterLocalId, elements, selectionType, correlationId, isSelectionInvalid) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.ATTRIBUTE_FILTER.CHANGE_SELECTION",
        correlationId,
        payload: {
            filterLocalId,
            elements,
            selectionType,
            isWorkingSelectionChange: true,
            isSelectionInvalid,
        },
    };
}
/**
 * Creates the ChangeAttributeFilterSelection command.
 *
 * @remarks
 * Dispatching this command will result in application of element selection for the dashboard attribute filter
 * with the provided id, or error in case of invalid update (e.g. non-existing `filterLocalId`).
 *
 * The {@link ChangeAttributeFilterSelectionPayload}'s `selectionType` and `elements` are derived from the
 * provided attribute filter.
 *
 * To convert {@link IDashboardFilter} to {@link @gooddata/sdk-model#IFilter} use {@link dashboardAttributeFilterToAttributeFilter}.
 * Converted filter can be used within the command's payload.
 *
 * @param filterLocalId - dashboard attribute filter's local id
 * @param filter - attribute filter to apply
 * @param correlationId - specify correlation id to use for this command. this will be included in all
 *  events that will be emitted during the command processing
 *
 * @public
 */
export function applyAttributeFilter(filterLocalId, filter, correlationId) {
    if (isAttributeFilterWithSelection(filter)) {
        return changeAttributeFilterSelection(filterLocalId, filterAttributeElements(filter) ?? { values: [] }, isPositiveAttributeFilter(filter) ? "IN" : "NOT_IN", correlationId);
    }
    if (isArbitraryAttributeFilter(filter)) {
        return replaceAttributeFilterItemSelection(filterLocalId, {
            arbitraryAttributeFilter: {
                displayForm: filterObjRef(filter),
                values: filter.arbitraryAttributeFilter.values,
                negativeSelection: filter.arbitraryAttributeFilter.negativeSelection ?? false,
                localIdentifier: filterLocalIdentifier(filter),
            },
        }, correlationId);
    }
    if (isMatchAttributeFilter(filter)) {
        return replaceAttributeFilterItemSelection(filterLocalId, {
            matchAttributeFilter: {
                displayForm: filterObjRef(filter),
                operator: filter.matchAttributeFilter.operator,
                literal: filter.matchAttributeFilter.literal,
                caseSensitive: filter.matchAttributeFilter.caseSensitive,
                negativeSelection: filter.matchAttributeFilter.negativeSelection,
                localIdentifier: filterLocalIdentifier(filter),
            },
        }, correlationId);
    }
    return undefined;
}
/**
 * A convenience function that will create ChangeAttributeFilterSelection command that will select all
 * elements of the dashboard attribute filter with the provided local id.
 *
 * @remarks
 * This is same as creating the ChangeAttributeFilterSelection command with empty elements and NOT_IN selection type.
 *
 * @param filterLocalId - dashboard attribute filter's local id
 * @param correlationId - specify correlation id to use for this command. this will be included in all
 *  events that will be emitted during the command processing
 *
 * @public
 */
export function resetAttributeFilterSelection(filterLocalId, correlationId) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.ATTRIBUTE_FILTER.CHANGE_SELECTION",
        correlationId,
        payload: {
            filterLocalId,
            elements: { uris: [] },
            selectionType: "NOT_IN",
        },
    };
}
/**
 * Creates the ReplaceAttributeFilterItemSelection command for applied filters.
 *
 * @remarks
 * Dispatching this command will result in replacement of the attribute filter item with the provided
 * filter in the dashboard filter context.
 *
 * @param filterLocalId - dashboard attribute filter's local id
 * @param filter - the replacement filter item
 * @param correlationId - specify correlation id to use for this command
 *
 * @internal
 */
export function replaceAttributeFilterItemSelection(filterLocalId, filter, correlationId, isSelectionInvalid) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.ATTRIBUTE_FILTER_ITEM.REPLACE_SELECTION",
        correlationId,
        payload: {
            filterLocalId,
            filter,
            isSelectionInvalid,
        },
    };
}
/**
 * Creates the ReplaceAttributeFilterItemSelection command for working filters.
 *
 * @param filterLocalId - dashboard attribute filter's local id
 * @param filter - the replacement filter item
 * @param correlationId - specify correlation id to use for this command
 *
 * @internal
 */
export function replaceWorkingAttributeFilterItemSelection(filterLocalId, filter, correlationId, isSelectionInvalid) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.ATTRIBUTE_FILTER_ITEM.REPLACE_SELECTION",
        correlationId,
        payload: {
            filterLocalId,
            filter,
            isWorkingSelectionChange: true,
            isSelectionInvalid,
        },
    };
}
/**
 * Creates the SetAttributeFilterDependentDateFilters command. Dispatching this command will result in setting a
 * relationship between one dashboard attribute filters and one or more date filters.
 *
 * When an attribute filter has a dependent date filter set up, the attribute elements that will be available in the attribute
 * filter will be influenced by the selection in the date filter. The attribute filter will show only those elements
 * for which a link exists to the selected elements in the dependent date filter.
 *
 *
 * @param filterLocalId - local id of filter that will be a child in the relationship
 * @param dependentDateFilters -
 * @param correlationId - specify correlation id to use for this command. this will be included in all
 *  events that will be emitted during the command processing
 *
 * @beta
 */
export function setAttributeFilterDependentDateFilters(filterLocalId, dependentDateFilters, correlationId) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.ATTRIBUTE_FILTER.SET_DEPENDENT_DATE_FILTERS",
        correlationId,
        payload: {
            filterLocalId,
            dependentDateFilters: dependentDateFilters,
        },
    };
}
/**
 * Creates the SetAttributeFilterParents command. Dispatching this command will result in setting a parent-child
 * relationship between two or more dashboard attribute filters.
 *
 * When an attribute filter has a parent set up, the attribute elements that will be available in the child
 * filter will be influenced by the selection in the parent. The child filter will show only those elements
 * for which a link exists to the selected elements in the parent.
 *
 * Take for example a model where there are continent and country attributes. You add continent and
 * country as filters onto a dashboard and establish parent-child relationship between them. When users select
 * some continents in the filter, the country filter will only show elements for countries on the selected
 * contents.
 *
 * @param filterLocalId - local id of filter that will be a child in the relationship
 * @param parentFilters - definition of the relationship to parent, this contains local id of the parent filter and
 *  one or more 'over' attributes. The 'over' attributes will be included when querying
 * @param correlationId - specify correlation id to use for this command. this will be included in all
 *  events that will be emitted during the command processing
 *
 * @beta
 */
export function setAttributeFilterParents(filterLocalId, parentFilters, correlationId) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.ATTRIBUTE_FILTER.SET_PARENTS",
        correlationId,
        payload: {
            filterLocalId,
            parentFilters: parentFilters,
        },
    };
}
/**
 * Creates the {@link ChangeFilterContextSelection} command.
 *
 * @remarks
 * Dispatching this command will result into setting provided dashboard filters to the current dashboard filter context.
 *
 * Only filters that are stored in the filter context can be applied (filters that are visible in the filter bar).
 * Filters will be matched via display form ref, duplicities will be omitted.
 * Date filter that does not match any visible option by the current date filter config will be also omitted.
 *
 * @public
 * @param filters - attribute filters and date filter to apply.
 * @param resetOthers - If true, filters not mentioned in the payload will be reset to All items selected/All time. Defaults to false.
 * @param correlationId - specify correlation id. It will be included in all events that will be emitted during the command processing.
 * @returns change filter selection command
 */
export function changeFilterContextSelection(filters, resetOthers = false, correlationId) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.CHANGE_SELECTION",
        correlationId,
        payload: {
            filters,
            resetOthers,
        },
    };
}
/**
 * Creates the {@link ChangeFilterContextSelection} command.
 *
 * @remarks
 * Dispatching this command will result into setting provided dashboard filters to the current dashboard filter context.
 *
 * Only filters that are stored in the filter context can be applied (filters that are visible in the filter bar).
 * Filters will be matched via display form ref, duplicities will be omitted.
 * Date filter that does not match any visible option by the current date filter config will be also omitted.
 *
 * @param params - params for the command creator
 * @internal
 * TODO: next major release can remove ByParams suffix and use this implementation instead of original cmd creator + other creators can be rewritten to use params object
 * https://gooddata.atlassian.net/browse/STL-700
 */
export function changeFilterContextSelectionByParams({ filters, attributeFilterConfigs = [], resetOthers = false, correlationId, tabLocalIdentifier, }) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.CHANGE_SELECTION",
        correlationId,
        payload: {
            filters,
            attributeFilterConfigs,
            resetOthers,
            tabLocalIdentifier,
        },
    };
}
/**
 * Creates the {@link ISetAttributeFilterDisplayForm} command.
 *
 * @remarks
 * Dispatching the commands will result into setting provided display form as a selected
 * display form for the attribute filter.
 *
 *
 * @beta
 * @param filterLocalId - local identifier of the filter the display form is changed for
 * @param displayForm - newly selected display form
 * @param isWorkingSelectionChange - determines if command updates working filter context or applied filter context. Applied filter context is default.
 * @param isResultOfMigration - internal value, specifies that filter change was caused by displayAsLabel
 *  ad-hoc migration, the param will be removed once the usage of displayAsLabel is migrated on database
 *  metadata level.
 * @returns change filter display form command
 */
export function setAttributeFilterDisplayForm(filterLocalId, displayForm, isWorkingSelectionChange, isResultOfMigration) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.ATTRIBUTE_FILTER.SET_DISPLAY_FORM",
        payload: {
            filterLocalId,
            displayForm,
            isWorkingSelectionChange,
            isResultOfMigration,
        },
    };
}
/**
 * Creates the {@link ISetAttributeFilterTitle} command.
 *
 * @remarks
 * Dispatching the commands will result into setting provided title as a selected
 * title for the attribute filter.
 *
 *
 * @beta
 * @param filterLocalId - local identifier of the filter the display form is changed for
 * @param title - newly added title
 * @param correlationId - specify correlation id. It will be included in all events that will be emitted during the command processing.
 * @returns change filter title command
 */
export function setAttributeFilterTitle(filterLocalId, title, correlationId) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.ATTRIBUTE_FILTER.SET_TITLE",
        correlationId,
        payload: {
            filterLocalId,
            title,
        },
    };
}
/**
 * Creates the {@link ISetAttributeFilterSelectionMode} command.
 *
 * @remarks
 * Dispatching the commands will result into setting provided selection mode as a selected
 * selection mode for the attribute filter.
 *
 *
 * @beta
 * @param filterLocalId - local identifier of the filter the selection mode is changed for
 * @param selectionMode - newly selected selection mode
 * @returns change filter selection mode command
 */
export function setAttributeFilterSelectionMode(filterLocalId, selectionMode) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.ATTRIBUTE_FILTER.SET_SELECTION_MODE",
        payload: {
            filterLocalId,
            selectionMode,
        },
    };
}
/**
 * Creates the AddDateFilter command. Dispatching this command will result in the addition
 * of another date filter with defined dimension to the dashboard's filter bar, at desired position,
 * or error in case of invalid update (e.g. wrong or duplicated date dimension/data set)
 *
 * The filter will be set for the date dimension provided by reference. When created, the filter will be
 * no-op - all time filter.
 *
 * @param dateDataset - specify date dimension/data set which will be used for filtering of all widgets
 * @param index - specify index among the filters at which the new filter should be placed.
 * The index starts at zero and there is convenience that index of -1 would add the filter at the end.
 * @param correlationId - specify correlation id to use for this command. this will be included in all
 *
 * @alpha
 */
export function addDateFilter(dateDataset, index, correlationId) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.DATE_FILTER.ADD",
        correlationId,
        payload: {
            dateDataset,
            index,
        },
    };
}
/**
 * Creates the RemoveDateFilters command. Dispatching this command will result in the removal
 * of dashboard's date filter with the provided date data set.
 *
 * @param dataSet - dashboard date filter's date data set ref
 * @param correlationId - specify correlation id to use for this command. this will be included in all
 *  events that will be emitted during the command processing
 * @beta
 */
export function removeDateFilter(dataSet, correlationId) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.DATE_FILTER.REMOVE",
        correlationId,
        payload: {
            dataSets: [dataSet],
        },
    };
}
/**
 * Creates the MoveDateFilter command. Dispatching this command will result in move of the dashboard date
 * filter with the provided dataSet to a new spot. The new spot is defined by index. For convenience the index
 * of -1 means move to the end of the filter list.
 *
 * @param dataSet - dashboard filter's dataSet - no duplicates allowed
 * @param index - specify index among the draggable filters (attribute filters and date filters with dataSet) at which the new filter should be placed.
 *  The index starts at zero and there is convenience that index of -1 would add the filter at the end.
 * @param correlationId - specify correlation id to use for this command. this will be included in all
 *  events that will be emitted during the command processing
 *
 * @beta
 */
export function moveDateFilter(dataSet, index, correlationId) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.DATE_FILTER.MOVE",
        correlationId,
        payload: {
            dataSet,
            index,
        },
    };
}
/**
 * Creates the {@link ISaveFilterView} command.
 *
 * @remarks
 * Dispatching this command will result into snapshotting of the current dashboard filter context into a
 * filter view that will be persisted. User can later apply it to the filter context to restore it to the
 * saved state.
 *
 * @alpha
 * @param name - name of the filter view under which it will be listed in UI.
 * @param isDefault - determine if new filter view should be set as a default.
 * @param correlationId - specify correlation id. It will be included in all events that will be emitted during the command processing.
 * @returns save filter view command
 */
export function saveFilterView(name, isDefault, correlationId) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.FILTER_VIEW.SAVE",
        correlationId,
        payload: {
            name,
            isDefault,
        },
    };
}
/**
 * Creates the {@link IDeleteFilterView} command.
 *
 * @remarks
 * Dispatching this command will result into deletion of the persisted filter view.
 *
 * @alpha
 * @param ref - ref of the filter view that must be deleted
 * @param correlationId - specify correlation id. It will be included in all events that will be emitted during the command processing.
 * @returns delete filter view command
 */
export function deleteFilterView(ref, correlationId) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.FILTER_VIEW.DELETE",
        correlationId,
        payload: {
            ref,
        },
    };
}
/**
 * Creates the {@link IApplyFilterView} command.
 *
 * @remarks
 * Dispatching this command will result into application of the persisted filter view.
 *
 * @alpha
 * @param ref - ref of the filter view that must be applied to the filter context.
 * @param correlationId - specify correlation id. It will be included in all events that will be emitted during the command processing.
 * @returns delete filter view command
 */
export function applyFilterView(ref, correlationId) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.FILTER_VIEW.APPLY",
        correlationId,
        payload: {
            ref,
        },
    };
}
/**
 * Creates the {@link ISetFilterViewAsDefault} command.
 *
 * @remarks
 * Dispatching this command will result into setting of the persisted filter view as a default one when
 * dashboard filter context is loaded or unsetting it from being applied automatically on load.
 *
 * @alpha
 * @param ref - ref of the filter view that must be set as a default one.
 * @param isDefault - determine if filter view identified by the provided ref should be marked as a default
 *      one. If yes, any existing filter view for the same user and dashboard will be marked as non default
 *      as only one can be set as default at the same time.
 * @param correlationId - specify correlation id. It will be included in all events that will be emitted during the command processing.
 * @returns delete filter view command
 */
export function setFilterViewAsDefault(ref, isDefault, correlationId) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.FILTER_VIEW.CHANGE_DEFAULT_STATUS",
        correlationId,
        payload: {
            ref,
            isDefault,
        },
    };
}
/**
 * Creates the {@link IReloadFilterViews} command.
 *
 * @remarks
 * Dispatching this command will result with refreshing of the cache with saved filter views from
 * persistent storage and updating the local cache in redux store.
 *
 * @alpha
 * @param correlationId - specify correlation id. It will be included in all events that will be emitted during the command processing.
 * @returns delete filter view command
 */
export function reloadFilterViews(correlationId) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.FILTER_VIEW.RELOAD",
        correlationId,
    };
}
/**
 * Creates the {@link IApplyFilterContextWorkingSelection} command.
 *
 * @param correlationId - specify correlation id. It will be included in all events that will be emitted during the command processing.
 * @returns apply all filters command
 *
 * @alpha
 */
export function applyFilterContextWorkingSelection(correlationId) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.APPLY_WORKING_SELECTION",
        correlationId,
    };
}
/**
 * Creates the {@link IResetFilterContextWorkingSelection} command.
 *
 * @param correlationId - specify correlation id. It will be included in all events that will be emitted during the command processing.
 * @returns apply reset working filters command
 *
 * @alpha
 */
export function resetFilterContextWorkingSelection(correlationId) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.RESET_WORKING_SELECTION",
        correlationId,
    };
}
/**
 * Creates the AddMeasureValueFilter command.
 *
 * @param measure - catalog measure whose value should be filtered
 * @param index - position among draggable filters where the new filter should be placed
 * @param correlationId - correlation id propagated through emitted events
 * @param localIdentifier - optional local identifier for the new filter
 * @param title - optional custom title for the new filter
 * @param mode - optional visibility mode for the new filter
 *
 * @alpha
 */
export function addMeasureValueFilter(measure, index, correlationId, localIdentifier, title, mode) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.MEASURE_VALUE_FILTER.ADD",
        correlationId,
        payload: {
            measure,
            index,
            localIdentifier,
            title,
            mode,
        },
    };
}
/**
 * Creates the RemoveMeasureValueFilters command for a single filter.
 *
 * @alpha
 * @param localIdentifier - local identifier of the measure value filter
 * @param correlationId - correlation id propagated through emitted events
 * @returns remove measure value filter command
 */
export function removeMeasureValueFilter(localIdentifier, correlationId) {
    return removeMeasureValueFilters([localIdentifier], correlationId);
}
/**
 * Creates the RemoveMeasureValueFilters command for a batch of filters. The handler processes
 * them in one pass — each removal emits its own `DashboardMeasureValueFilterRemoved` event and
 * the whole batch settles with a single `DashboardFilterContextChanged`.
 *
 * @alpha
 * @param localIdentifiers - local identifiers of the measure value filters to remove
 * @param correlationId - correlation id propagated through emitted events
 */
export function removeMeasureValueFilters(localIdentifiers, correlationId) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.MEASURE_VALUE_FILTER.REMOVE",
        correlationId,
        payload: {
            localIdentifiers,
        },
    };
}
/**
 * Creates the MoveMeasureValueFilter command.
 *
 * @alpha
 * @param localIdentifier - local identifier of the measure value filter
 * @param index - target index among draggable filters
 * @param correlationId - correlation id propagated through emitted events
 * @returns move measure value filter command
 */
export function moveMeasureValueFilter(localIdentifier, index, correlationId) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.MEASURE_VALUE_FILTER.MOVE",
        correlationId,
        payload: {
            localIdentifier,
            index,
        },
    };
}
/**
 * Creates the ChangeMeasureValueFilterCondition command.
 *
 * @remarks
 * Dispatching this command updates the conditions of an existing measure value filter. To clear
 * the filter (set it back to "All"), pass undefined or an empty array.
 *
 * @param localIdentifier - local identifier of the measure value filter to update
 * @param conditions - new conditions to apply, or undefined to clear
 * @param correlationId - correlation id propagated through emitted events
 *
 * @alpha
 */
export function changeMeasureValueFilterCondition(localIdentifier, conditions, correlationId) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.MEASURE_VALUE_FILTER.CHANGE_CONDITION",
        correlationId,
        payload: {
            localIdentifier,
            conditions,
        },
    };
}
/**
 * Creates the ChangeMeasureValueFilterCondition command for working filter context changes.
 *
 * @alpha
 * @param localIdentifier - local identifier of the measure value filter to update
 * @param conditions - new conditions to apply, or undefined to clear
 * @param correlationId - correlation id propagated through emitted events
 * @returns change measure value filter condition command
 */
export function changeWorkingMeasureValueFilterCondition(localIdentifier, conditions, correlationId) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.MEASURE_VALUE_FILTER.CHANGE_CONDITION",
        correlationId,
        payload: {
            localIdentifier,
            conditions,
            isWorkingSelectionChange: true,
        },
    };
}
/**
 * Creates the {@link ISetMeasureValueFilterDimensionality} command.
 *
 * @alpha
 * @param localIdentifier - local identifier of the measure value filter to update
 * @param dimensionality - fixed dashboard-level dimensionality, or undefined to inherit per-widget granularity
 * @param correlationId - correlation id propagated through emitted events
 * @returns set measure value filter dimensionality command
 */
export function setMeasureValueFilterDimensionality(localIdentifier, dimensionality, correlationId) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.MEASURE_VALUE_FILTER.SET_DIMENSIONALITY",
        correlationId,
        payload: {
            localIdentifier,
            dimensionality,
        },
    };
}
/**
 * Creates the {@link ISetMeasureValueFilterTitle} command.
 *
 * @alpha
 * @param filterLocalId - local identifier of the measure value filter
 * @param title - custom title, or undefined to reset to the default metric title
 * @param correlationId - correlation id propagated through emitted events
 * @returns change measure value filter title command
 */
export function setMeasureValueFilterTitle(filterLocalId, title, correlationId) {
    return {
        type: "GDC.DASH/CMD.FILTER_CONTEXT.MEASURE_VALUE_FILTER.SET_TITLE",
        correlationId,
        payload: {
            filterLocalId,
            title,
        },
    };
}
