package com.zivilon.cindercore_modlist.util;

import java.util.Map;
import java.util.ArrayList;
import java.util.List;

import cpw.mods.fml.common.registry.GameData.GameDataSnapshot;

import com.zivilon.cindercore_modlist.CinderCoreModlist;
import com.zivilon.cindercore_modlist.FallbackEntry;

public class HandshakeUtils {

    private static boolean shouldRemove(Map.Entry<String, Integer> entry, Map<Integer, Integer> fallbackMap) {
        return fallbackMap.containsKey(entry.getValue());
    }

    public static GameDataSnapshot modifyGameDataSnapshot(GameDataSnapshot itemlist, Map<Integer, Integer> fallbackMap) {
        List<String> removedKeys = new ArrayList<>();
        itemlist.idMap.entrySet().removeIf(entry -> {
            boolean toRemove = shouldRemove(entry, fallbackMap);
            if (toRemove) {
                removedKeys.add(entry.getKey());
            }
            return toRemove;
        });

        itemlist.blockSubstitutions.removeIf(removedKeys::contains);
        itemlist.itemSubstitutions.removeIf(removedKeys::contains);
        return itemlist;
    }

    public static void printGameDataSnapshot(GameDataSnapshot itemlist) {
        System.out.println("[CinderCoreModlist] Current GameDataSnapshot Items:");
        for (Map.Entry<String, Integer> entry : itemlist.idMap.entrySet()) {
            System.out.println("Name: " + entry.getKey() + ", ID: " + entry.getValue());
        }
    }

}