package eu.mhsl.minenet.minigames.command;

import net.minestom.server.command.builder.Command;
import net.minestom.server.command.builder.condition.CommandCondition;
import net.minestom.server.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

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

public class PrivilegedCommand extends Command {
    private final List<CommandCondition> conditions = new ArrayList<>();
    public PrivilegedCommand(@NotNull String name, @Nullable String... aliases) {
        super(name, aliases);
        construct();
    }

    public PrivilegedCommand(@NotNull String name) {
        super(name);
        construct();
    }

    private void construct() {
        addCondition(isPrivileged());

        setCondition((sender, commandString) -> conditions.parallelStream().allMatch(condition -> condition.canUse(sender, commandString)));
    }

    protected CommandCondition isPrivileged() {
        return (sender, commandString) -> ((Player) sender).getPermissionLevel() == 4;
    }

    protected void addCondition(CommandCondition condition) {
        conditions.add(condition);
    }
}
