package io.github.thatsmusic99.headsplus.commands.maincommand;

import io.github.thatsmusic99.headsplus.commands.CommandInfo;
import io.github.thatsmusic99.headsplus.commands.IHeadsPlusCommand;
import io.github.thatsmusic99.headsplus.config.HeadsPlusMessagesManager;
import io.github.thatsmusic99.headsplus.config.customheads.ConfigCustomHeads;
import io.github.thatsmusic99.headsplus.config.defaults.HeadsXEnums;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;

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

@CommandInfo(
        commandname = "restore",
        permission = "headsplus.maincommand.restore",
        maincommand = true,
        usage = "/hp restore <Head Name>",
        descriptionPath = "descriptions.hp.restore"
)
public class RestoreCommand implements IHeadsPlusCommand {

    @Override
    public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
        if (args.length > 1) {
            try {
                HeadsXEnums headToBeAdded = HeadsXEnums.valueOf(args[1].toUpperCase());
                // TODO - should be heads.yml
                ConfigCustomHeads.get().set("heads." + headToBeAdded.name, null);
                ConfigCustomHeads.get().addHead(headToBeAdded.texture,
                        true,
                        headToBeAdded.displayName,
                        headToBeAdded.section,
                        "default",
                        true);
                HeadsPlusMessagesManager.get().sendMessage("commands.restore.restored-head", sender, "{head}", args[1]);
                return true;
            } catch (IllegalArgumentException ex) {
                HeadsPlusMessagesManager.get().sendMessage("commands.restore.invalid-head", sender, "{head}", args[1]);
                return true;
            }
        } else {
            HeadsPlusMessagesManager.get().sendMessage("commands.errors.invalid-args", sender);
            return false;
        }
    }

    @Override
    public boolean shouldEnable() {
        return true;
    }

    @Override
    public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, @NotNull String[] args) {
        List<String> results = new ArrayList<>();
        if (args.length == 2) {
            List<String> headNames = new ArrayList<>();
            for (HeadsXEnums head : HeadsXEnums.values()) {
                headNames.add(head.name().toLowerCase());
            }
            StringUtil.copyPartialMatches(args[1], headNames, results);
        }
        return results;
    }
}

@@ -183,24 +183,84 @@
 lusCommand;%0A
+import io.github.thatsmusic99.headsplus.config.ConfigHeads;%0A
 import io.gi
@@ -1256,66 +1256,14 @@
     
-// TODO - should be heads.yml%0A                ConfigCustom
+Config
 Head
@@ -1330,30 +1330,24 @@
       Config
-Custom
 Heads.get().
@@ -1350,92 +1350,60 @@
 t().
-addHead(headToBeAdded.texture,%0A                        true,%0A                       
+set(%22heads.%22 + headToBeAdded.name + %22.display-name%22,
  hea
@@ -1424,17 +1424,18 @@
 playName
-,
+);
 %0A       
@@ -1447,101 +1447,94 @@
     
-        headToBeAdded.section,%0A                        %22default%22,%0A                        tru
+ConfigHeads.get().set(%22heads.%22 + headToBeAdded.name + %22.texture%22, headToBeAdded.textur
 e);%0A

Make /hp restore use heads.yml