/**
 * Generates Cartesian product of filter values.
 */
export class Combinator {
    /**
     * Generates all combinations of input filters.
     * Example: { state: ['UP', 'DL'], year: [2024] } ->
     * [ { state: 'UP', year: 2024 }, { state: 'DL', year: 2024 } ]
     */
    static generateCombinations(filters) {
        const keys = Object.keys(filters);
        if (keys.length === 0)
            return [{}];
        const combinations = [{}];
        for (const key of keys) {
            const filterValue = filters[key];
            // Only treat as combinatorial if it's an array. Strings/numbers are literal values.
            const values = Array.isArray(filterValue) ? Array.from(new Set(filterValue)) : [filterValue];
            const newCombinations = [];
            for (const value of values) {
                for (const combination of combinations) {
                    newCombinations.push({ ...combination, [key]: value });
                }
            }
            combinations.length = 0;
            combinations.push(...newCombinations);
        }
        return combinations;
    }
}
