package stream.flarebot.flarebot.util;

import net.dv8tion.jda.core.requests.RestAction;
import stream.flarebot.flarebot.commands.Command;
import stream.flarebot.flarebot.commands.moderation.PruneCommand;
import stream.flarebot.flarebot.objects.RestActionWrapper;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

public class ConfirmLib {

    private static final ExpiringMap<String, List<RestActionWrapper>> confirmMap = new ExpiringMap<>(TimeUnit.MINUTES.toMillis(1));

    public static void pushAction(String userID, RestActionWrapper action) {
        if (confirmMap.containsKey(userID)) {
            List<RestActionWrapper> actions = confirmMap.get(userID);
            if (actions.stream().filter(wrapper -> wrapper.getOrigin().equals(action.getOrigin())).count() == 0) {
                actions.add(action);
            }
        } else {
            ArrayList<RestActionWrapper> actions = new ArrayList<>();
            actions.add(action);
            confirmMap.put(userID, actions);
        }
    }

    public static RestAction get(String userID, Class<? extends Command> command) {
        if (confirmMap.containsKey(userID)) {
            List<RestActionWrapper> wrappers = confirmMap.get(userID);
            return ((RestActionWrapper) wrappers.stream().filter(wrapper -> wrapper.getOrigin().equals(command)).toArray()[0]).getAction();
        }
        return null;
    }

    public static void removeUser(String userID) {
        if(confirmMap.containsKey(userID)) {
            confirmMap.remove(userID);
        }
    }

    public static boolean checkExists(String userID, Class<? extends Command> command) {
        if (confirmMap.containsKey(userID)) {
            List<RestActionWrapper> wrappers = confirmMap.get(userID);
            return wrappers.stream().filter(wrapper -> wrapper.getOrigin().equals(command)).count() > 0;
        }
        return false;
    }

    public static void clearConfirmMap() {
        ConfirmLib.clearConfirmMap(false);
    }

    public static void clearConfirmMap(boolean force) {
        confirmMap.purge(force);
    }


    public static void remove(String id, Class<? extends PruneCommand> command) {
        if (checkExists(id, command)) {
            confirmMap.get(id).removeIf(restActionWrapper -> restActionWrapper.getOrigin().equals(command));
        }
    }

}

@@ -82,16 +82,65 @@
 Action;%0A
+import org.eclipse.jetty.util.ConcurrentHashSet;%0A
 import s
@@ -173,32 +173,32 @@
 mmands.Command;%0A
-
 import stream.fl
@@ -328,39 +328,10 @@
 til.
-ArrayList;%0Aimport java.util.Lis
+Se
 t;%0Ai
@@ -440,19 +440,18 @@
 String, 
-Lis
+Se
 t%3CRestAc
@@ -654,35 +654,34 @@
 ) %7B%0A            
-Lis
+Se
 t%3CRestActionWrap
@@ -914,24 +914,18 @@
         
-ArrayLis
+Se
 t%3CRestAc
@@ -955,16 +955,24 @@
 new 
-ArrayLis
+ConcurrentHashSe
 t%3C%3E(
@@ -1203,35 +1203,34 @@
 ) %7B%0A            
-Lis
+Se
 t%3CRestActionWrap
@@ -1750,11 +1750,10 @@
     
-Lis
+Se
 t%3CRe

Change to set