import { type SegmentationGroupType } from '@material-hu/components/composed-components/peopleExperience/types';

export type FilterState = {
  selectedItems: Map<number, Set<number>>;
  selectAllGroups: Set<number>;
  deselectedItems: Map<number, Set<number>>;
  expandedGroups: Set<number>;
  groupsByType: Map<SegmentationGroupType, Set<number>>;
  isDirty: boolean;
};

export type FilterAction =
  | { type: 'TOGGLE_ITEM'; groupId: number; itemId: number; itemName: string }
  | { type: 'SELECT_ALL_GROUP'; groupId: number }
  | { type: 'DESELECT_ALL_GROUP'; groupId: number }
  | { type: 'SET_GROUP_EXPANSION'; groupId: number; expanded: boolean }
  | { type: 'INITIALIZE_FILTERS'; filters: SerializedFilterState }
  | {
      type: 'REGISTER_GROUP_TYPE';
      groupId: number;
      groupType: SegmentationGroupType;
    }
  | { type: 'RESET_ALL' };

export type SerializedFilterState = {
  selectedItems: Record<number, number[]>;
  selectAllGroups: number[];
  deselectedItems: Record<number, number[]>;
  groupsByType: Record<SegmentationGroupType, number[]>;
};

export type SelectAllState = 'none' | 'all' | 'indeterminate';

export type GroupMetadata = {
  id: number;
  displayName: string;
  indexCount: number;
  indexItems: { id: number; name: string }[];
  pickedItems: { id: number; name: string }[];
};
