package land.chipmunk.chipmunkmod.config;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.format.NamedTextColor;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.configurate.objectmapping.ConfigSerializable;

@ConfigSerializable
public class Configuration {
    public CommandManager commands = new CommandManager();
    public CommandCore core = new CommandCore();
    public Bots bots = new Bots();
    public CustomChat customChat = new CustomChat();
    public SelfCare selfCare = new SelfCare();
    public String autoSkinUsername = "off";
    public String autoPrefix = "off";

    @ConfigSerializable
    public static class CommandManager {
        public String prefix = ".";
    }

    @ConfigSerializable
    public static class CommandCore {
        public BoundingBox relativeArea = BoundingBox.fromCorners(new BlockPos(0, 0, 0), new BlockPos(15, 0, 15));
        public boolean logCommands = false;
    }

    @ConfigSerializable
    public static class Bots {
        public BotInfo hbot = new BotInfo("#", null);
        public BotInfo sbot = new BotInfo(":", null);
        public BotInfo chipmunk = new BotInfo("'", null);
        public ChomeNSBotInfo chomens = new ChomeNSBotInfo("*", null, true);
        public BotInfo fnfboyfriend = new BotInfo("~", null);
        public BotInfo qilk = new BotInfo(">", null);
        public BotInfo nbot = new BotInfo("?", null);
        public BotInfo kittycorp = new BotInfo("^", null);
        public TestBotInfo testbot = new TestBotInfo("-", null);
    }

    @ConfigSerializable
    public static class TestBotInfo {
        public String prefix;
        public @Nullable String webhookUrl;

        public TestBotInfo () {
        }

        public TestBotInfo (final String prefix, @Nullable final String webhookUrl) {
            this.prefix = prefix;
            this.webhookUrl = webhookUrl;
        }
    }

    @ConfigSerializable
    public static class ChomeNSBotInfo extends BotInfo {
        public boolean autoValidate;

        public ChomeNSBotInfo () {
        }

        public ChomeNSBotInfo (final String prefix, @Nullable final String key, final boolean autoValidate) {
            super(prefix, key);
            this.autoValidate = autoValidate;
        }
    }

    @ConfigSerializable
    public static class BotInfo {
        public String prefix;
        public @Nullable String key;

        public BotInfo () {
        }

        public BotInfo (final String prefix, @Nullable final String key) {
            this.prefix = prefix;
            this.key = key;
        }
    }

    @ConfigSerializable
    public static class SelfCare {
        public boolean cspy = true;
        public boolean gameMode = true;
        public boolean op = true;
    }

    @ConfigSerializable
    public static class CustomChat {
        public boolean enabled = true;
        public boolean onlyUseWhenNecessary = false;

        public @NotNull Component format =
                // chipmunk's custom chat format
                // §8[§7Chat§8] §aUSERNAME§8 › §7MESSAGE
                // but with `Chat` replaced with `ChipmunkMod`
                // and click events and hover events added
                Component
                        .translatable("[%s] %s › %s", NamedTextColor.DARK_GRAY,
                                      Component.text("ChipmunkMod", NamedTextColor.GREEN)
                                              .hoverEvent(
                                                      HoverEvent.showText(
                                                              Component.text(
                                                                      "Click here to open the ChipmunkMod source code (chayapak's fork)",
                                                                      NamedTextColor.GREEN
                                                              )
                                                      )
                                              )
                                              .clickEvent(ClickEvent.openUrl("https://code.chipmunk.land/ChomeNS/chipmunkmod")),
                                      Component.selector("@s").color(NamedTextColor.GREEN),
                                      Component.text("MESSAGE", NamedTextColor.GRAY)
                                              .hoverEvent(
                                                      HoverEvent.showText(
                                                              Component.text(
                                                                      "Click here to copy the message to your clipboard",
                                                                      NamedTextColor.GREEN
                                                              )
                                                      )
                                              )
                                              .clickEvent(ClickEvent.copyToClipboard("MESSAGE"))
                        );
    }
}
