// 
// Decompiled by Procyon v0.6.0
// 

package com.hypixel.hytale.server.core.modules.accesscontrol.commands;

import java.util.Set;
import java.util.UUID;
import com.hypixel.hytale.server.core.Message;
import java.util.concurrent.CompletableFuture;
import com.hypixel.hytale.server.core.command.system.CommandContext;
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgumentType;
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgTypes;
import com.hypixel.hytale.server.core.auth.ProfileServiceClient;
import com.hypixel.hytale.server.core.command.system.arguments.system.RequiredArg;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.modules.accesscontrol.provider.HytaleWhitelistProvider;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractAsyncCommand;

public class WhitelistRemoveCommand extends AbstractAsyncCommand
{
    @Nonnull
    private final HytaleWhitelistProvider whitelistProvider;
    @Nonnull
    private final RequiredArg<ProfileServiceClient.PublicGameProfile> playerArg;
    
    public WhitelistRemoveCommand(@Nonnull final HytaleWhitelistProvider whitelistProvider) {
        super("remove", "server.commands.whitelist.remove.desc");
        this.playerArg = this.withRequiredArg("player", "server.commands.whitelist.remove.player.desc", ArgTypes.GAME_PROFILE_LOOKUP);
        this.whitelistProvider = whitelistProvider;
    }
    
    @Nonnull
    @Override
    protected CompletableFuture<Void> executeAsync(@Nonnull final CommandContext context) {
        final ProfileServiceClient.PublicGameProfile profile = this.playerArg.get(context);
        if (profile == null) {
            return CompletableFuture.completedFuture((Void)null);
        }
        final UUID uuid = profile.getUuid();
        final Message displayMessage = Message.raw(profile.getUsername()).bold(true);
        if (this.whitelistProvider.modify(list -> list.remove(uuid))) {
            context.sendMessage(Message.translation("server.modules.whitelist.removalSuccess").param("uuid", displayMessage));
        }
        else {
            context.sendMessage(Message.translation("server.modules.whitelist.uuidNotWhitelisted").param("uuid", displayMessage));
        }
        return CompletableFuture.completedFuture((Void)null);
    }
}
