package eu.mhsl.minenet.minigames.command.privileged;

import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
import eu.mhsl.minenet.minigames.instance.room.Room;
import eu.mhsl.minenet.minigames.score.tournament.MemorialConfiguration;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.minestom.server.command.builder.arguments.ArgumentString;
import net.minestom.server.command.builder.arguments.ArgumentType;
import net.minestom.server.command.builder.suggestion.SuggestionEntry;
import net.minestom.server.entity.Player;
import net.minestom.server.item.Material;


public class SetMemorialCommand extends PrivilegedCommand {
    public SetMemorialCommand() {
        super("setMemorial");

        ArgumentString materialArgument = ArgumentType.String("material");
        ArgumentString titleArgument = ArgumentType.String("title");
        ArgumentString loreArgument = ArgumentType.String("lore");

        materialArgument.setSuggestionCallback((sender, context, suggestion) -> {
            Material
                    .values()
                    .stream()
                    .map(material -> new SuggestionEntry(material.name(), Component.text(material.name())))
                    .forEach(suggestion::addEntry);
        });

        addSyntax((sender, context) -> {
            Room
                    .getRoom((Player) sender)
                    .orElseThrow()
                    .getTournament()
                    .setMemorialConfiguration(
                            new MemorialConfiguration(
                                    Material.fromNamespaceId(context.get(materialArgument)),
                                    context.get(titleArgument),
                                    context.get(loreArgument)
                            )
                    );

            sender.sendMessage(
                    Component.text()
                            .append(Component.text("Memorial gesetzt:", NamedTextColor.GOLD))
                            .appendNewline()
                            .append(Component.text(context.get(materialArgument), NamedTextColor.AQUA))
                            .appendNewline()
                            .append(Component.text(context.get(titleArgument), NamedTextColor.RED))
                            .appendNewline()
                            .append(Component.text(context.get(loreArgument), NamedTextColor.DARK_RED))
                            .build()
            );
        }, materialArgument, titleArgument, loreArgument);
    }
}
