package de.hessj.environmentex;

import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;

public class PinFeature implements TabCompleter {
    public static File pinYml = new File(App.main.getDataFolder() + "/pins.yml");
    public static FileConfiguration pinConfig = YamlConfiguration.loadConfiguration(pinYml);
    @Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player)) {
        return Collections.emptyList();
    }
    Player player = (Player) sender;
    UUID playerId = player.getUniqueId();

    if (args.length == 1) {
        return Arrays.asList("set", "list", "remove", "follow", "unfollow");
    }

    if (args.length == 2) {
        String subCommand = args[0].toLowerCase();

        if (subCommand.equals("set")) {
            return Collections.emptyList(); // Spieler gibt selbst einen Namen ein
        }

        if (subCommand.equals("list") || subCommand.equals("unfollow")) {
            return Collections.emptyList(); // Keine Argumente notwendig
        }

        if (subCommand.equals("remove") || subCommand.equals("follow")) {
            ConfigurationSection playerSection = PinFeature.pinConfig.getConfigurationSection(playerId.toString());
            if (playerSection != null) {
                return playerSection.getKeys(false).stream()
                        .sorted(Comparator.comparingInt(Integer::parseInt))
                        .collect(Collectors.toList());
            }
        }
    }
    return Collections.emptyList();
}

//For more see EnvironmentExCommands.java

}
