/**
 * ExcludedStore - Persists "Mark not needed" (excluded) node IDs to localStorage.
 * Keyed by connectionId + platformType. Later will wire to DB.
 */
const ExcludedStore = {
    getStorageKey(connectionId, platformType) {
        return `chameleonExcluded_${platformType || 'Unknown'}_${connectionId || 0}`;
    },
    getExcludedIds(connectionId, platformType) {
        try {
            const key = this.getStorageKey(connectionId, platformType);
            const raw = localStorage.getItem(key);
            if (!raw) return new Set();
            const arr = JSON.parse(raw);
            return new Set(Array.isArray(arr) ? arr : []);
        } catch (e) {
            console.warn('ExcludedStore.getExcludedIds:', e);
            return new Set();
        }
    },
    setExcluded(connectionId, platformType, nodeId, excluded) {
        const ids = this.getExcludedIds(connectionId, platformType);
        if (excluded) {
            ids.add(nodeId);
        } else {
            ids.delete(nodeId);
        }
        const key = this.getStorageKey(connectionId, platformType);
        localStorage.setItem(key, JSON.stringify([...ids]));
        return ids;
    },
    toggleExcluded(connectionId, platformType, nodeId) {
        const ids = this.getExcludedIds(connectionId, platformType);
        const excluded = !ids.has(nodeId);
        return this.setExcluded(connectionId, platformType, nodeId, excluded);
    },
    isExcluded(connectionId, platformType, nodeId) {
        return this.getExcludedIds(connectionId, platformType).has(nodeId);
    },
    getExcludedCount(connectionId, platformType) {
        return this.getExcludedIds(connectionId, platformType).size;
    }
};
