package dev.drawethree.xprison.gangs.commands.impl;

import dev.drawethree.xprison.gangs.commands.GangCommand;
import dev.drawethree.xprison.gangs.commands.GangSubCommand;
import dev.drawethree.xprison.gangs.model.Gang;
import me.lucko.helper.utils.Players;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public final class GangSaveSubCommand extends GangSubCommand {

    public GangSaveSubCommand(GangCommand command) {
        super(command, "save", "savegang");
    }

    @Override
    public String getUsage() {
        return ChatColor.RED + "/gang save";
    }

    @Override
    public boolean execute(CommandSender sender, List<String> args) {
        if (sender instanceof Player) {
            Player p = (Player) sender;
            if (args.size() == 0) {
                p.sendMessage(ChatColor.GREEN + "All Gangs Saved!");
                return this.command.getPlugin().getGangsManager().saveGangs();
            } else {
                p.sendMessage(ChatColor.RED + "Invalid Usage! " + this.getUsage());
            }
        }
        return false;
    }


    @Override
    public boolean canExecute(CommandSender sender) {
        return true;
    }

    @Override
    public List<String> getTabComplete() {
        List<String> tabComplete = new ArrayList<>();
        tabComplete.addAll(Players.all().stream().map(Player::getName).collect(Collectors.toList()));
        tabComplete.addAll(this.command.getPlugin().getGangsManager().getAllGangs().stream().map(Gang::getName).collect(Collectors.toList()));
        return tabComplete;
    }
}

