package fr.Skydust.JdrBot.utils;

import fr.Skydust.JdrBot.JdrBot;
import fr.Skydust.JdrBot.enums.MessageType;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;

import java.awt.*;

public class Utils {
	/**
	 * Simple function to check if a string is parseable as an integer.
	 * @param str The string to try to parse.
	 * @return True is the string is parseable, false otherwise.
	 */
	public static boolean IsInt(String str) {
		try {
			Integer.parseInt(str);
			return true;
		} catch(Exception e) {
			return false;
		}
	}


	/**
	 * An utility function to send a message into a discord channel.
	 * @param channel The channel to send the message to.
	 * @param msgType The type of message to send.
	 * @param message The message.
	 */
	public static void sendMessage(MessageChannel channel, MessageType msgType, String message) {
		Color c = Color.GREEN;
		String title = "Message";

		if(msgType == MessageType.ERROR) {
			c = Color.RED;
			title = "Erreur";
		}

		channel.sendMessage(new MessageCreateBuilder().setEmbeds(new EmbedBuilder().
				setDescription(message)
				.setTitle(title, null)
				.setFooter("", JdrBot.jda.getSelfUser().getAvatarUrl())
				.setColor(c)
				.build()).build()).queue();
	}
}
