package com.loganmagnan.eventcore.commands;

import com.loganmagnan.eventcore.EventCore;
import com.loganmagnan.eventcore.menusystem.menus.ChatManageMenu;
import com.loganmagnan.eventcore.utils.ColorUtils;
import com.loganmagnan.eventcore.utils.Constants;
import com.loganmagnan.eventcore.utils.Utils;
import com.loganmagnan.eventcore.utils.command.BaseCommand;
import com.loganmagnan.eventcore.utils.command.Command;
import com.loganmagnan.eventcore.utils.command.CommandArguments;
import org.bukkit.entity.Player;

public class ChatCommand extends BaseCommand {

    private EventCore main = EventCore.getInstance();

    @Command(name = "chat", permission = "eventcore.command.chat")
    @Override
    public void executeAs(CommandArguments command) {
        Player player = command.getPlayer();

        String[] args = command.getArgs();

        if (args.length == 0) {
            for (String string : Constants.COMMAND_MESSAGES.get("chat.help")) {
                player.sendMessage(ColorUtils.getMessageType(string.replace("%line%", Utils.chatBar)));
            }
        } else {
            switch (args[0]) {
                case "manage":
                    new ChatManageMenu(this.main.getPlayerMenuUtil(player), this.main.getChatManager().getDelayAmount()).open(player);

                    break;
                case "toggle":
                    this.main.getChatManager().toggleChat(player);

                    break;
                case "slow":
                    if (args[1] == null) {
                        player.sendMessage(ColorUtils.getMessageType(Constants.COMMAND_MESSAGES.get("chat.slow.invalid-argument").get(0)));

                        return;
                    }

                    if (!Utils.isNumeric(args[1])) {
                        player.sendMessage(ColorUtils.getMessageType(Constants.COMMAND_MESSAGES.get("chat.slow.invalid-amount").get(0)));

                        return;
                    }

                    int amount = Integer.parseInt(args[1]);

                    this.main.getChatManager().slowChat(player, amount);

                    break;
                case "clear":
                    this.main.getChatManager().clearChat(player);

                    break;
            }
        }
    }
}
