package org.atmospheregames.network.command;

import com.google.gson.JsonObject;
import com.jonahseguin.drink.annotation.Command;
import com.jonahseguin.drink.annotation.Sender;
import org.atmospheregames.network.Network;
import org.atmospheregames.network.util.Style;
import org.bukkit.command.CommandSender;

public class NetworkCommand {

    private final Network plugin;

    public NetworkCommand(Network plugin) {
        this.plugin = plugin;
    }
    @Command(name = "info", desc = "Show information about a server", usage = "<server>")
    public void networkInfo(@Sender CommandSender sender, String target) {
        JsonObject object = plugin.getRedisClient().getRedisListener().getCachedMessages().get(target);

        if (object == null) {
            sender.sendMessage(Style.translate("&cUnable to find the server &n" + target + "&r&c. &7Remember, this command is case-sensitive."));
            return;
        }

        sender.sendMessage(Style.CHAT_BAR);
        sender.sendMessage(Style.translate("&b&lServer Information for &n" + target));
        sender.sendMessage(Style.CHAT_BAR);
        sender.sendMessage(Style.translate(" &3• &fStatus: " + (object.get("online").getAsBoolean() ? "&aOnline" : "&cOffline") + (object.get("whitelisted").getAsBoolean() ? " &7(&eWhitelisted&7)" : "")));
        sender.sendMessage(Style.translate(" &3• &fOnline: &b" + object.get("onlinePlayers").getAsString() + "&7/&b" + object.get("onlinePlayerLimit").getAsString()));
        sender.sendMessage(Style.translate(" &3• &fTPS: &r" + Style.tps(object.get("ticksPerSecond").getAsDouble())));
        sender.sendMessage(Style.CHAT_BAR);
    }

}
