package de.hessj.helper;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack;
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.format.TextDecoration;
import net.md_5.bungee.api.ChatColor;

public class Helper {

    public enum Type {
        ERROR,
        SUCCESS,
        INFO,
        OK
    }

    public Component R3SMessage(Type type, String msg) {

        switch (type) {
            case ERROR:
                return Component.text(msg).color(TextColor.fromHexString("#c0392b")).decoration(TextDecoration.ITALIC,
                        false);
            case INFO:
                return Component.text(msg).color(TextColor.fromHexString("#3498db")).decoration(TextDecoration.ITALIC,
                        false);
            case OK:
                return Component.text(msg).color(TextColor.fromHexString("#2ecc71")).decoration(TextDecoration.ITALIC,
                        false);
            case SUCCESS:
                return Component.text(msg).color(TextColor.fromHexString("#2ecc71")).decoration(TextDecoration.ITALIC,
                        false);
        }
        return Component.text(ChatColor.WHITE + msg);

    }

    public boolean isInteractable(Block b) {
        List<Material> interactableBlocks = new ArrayList<Material>();
        interactableBlocks.add(Material.CHEST);
        interactableBlocks.add(Material.TRAPPED_CHEST);
        interactableBlocks.add(Material.ENDER_CHEST);
        interactableBlocks.add(Material.BARREL);
        interactableBlocks.add(Material.SHULKER_BOX);
        interactableBlocks.add(Material.HOPPER);
        interactableBlocks.add(Material.DISPENSER);
        interactableBlocks.add(Material.DROPPER);
        interactableBlocks.add(Material.CRAFTING_TABLE);
        interactableBlocks.add(Material.FURNACE);
        interactableBlocks.add(Material.BLAST_FURNACE);
        interactableBlocks.add(Material.SMOKER);
        interactableBlocks.add(Material.CARTOGRAPHY_TABLE);
        interactableBlocks.add(Material.SMITHING_TABLE);
        interactableBlocks.add(Material.LOOM);
        interactableBlocks.add(Material.STONECUTTER);
        interactableBlocks.add(Material.GRINDSTONE);
        interactableBlocks.add(Material.ANVIL);
        interactableBlocks.add(Material.CHIPPED_ANVIL);
        interactableBlocks.add(Material.DAMAGED_ANVIL);
        interactableBlocks.add(Material.LEVER);
        interactableBlocks.add(Material.STONE_BUTTON);
        interactableBlocks.add(Material.OAK_BUTTON);
        interactableBlocks.add(Material.BIRCH_BUTTON);
        interactableBlocks.add(Material.BAMBOO_BUTTON);
        interactableBlocks.add(Material.DARK_OAK_BUTTON);
        interactableBlocks.add(Material.SPRUCE_BUTTON);
        interactableBlocks.add(Material.JUNGLE_BUTTON);
        interactableBlocks.add(Material.ACACIA_BUTTON);
        interactableBlocks.add(Material.STONE_PRESSURE_PLATE);
        interactableBlocks.add(Material.OAK_PRESSURE_PLATE);
        interactableBlocks.add(Material.BIRCH_PRESSURE_PLATE);
        interactableBlocks.add(Material.BAMBOO_PRESSURE_PLATE);
        interactableBlocks.add(Material.DARK_OAK_PRESSURE_PLATE);
        interactableBlocks.add(Material.SPRUCE_PRESSURE_PLATE);
        interactableBlocks.add(Material.JUNGLE_PRESSURE_PLATE);
        interactableBlocks.add(Material.ACACIA_PRESSURE_PLATE);
        interactableBlocks.add(Material.LIGHT_WEIGHTED_PRESSURE_PLATE);
        interactableBlocks.add(Material.HEAVY_WEIGHTED_PRESSURE_PLATE);
        interactableBlocks.add(Material.TRIPWIRE_HOOK);
        interactableBlocks.add(Material.COMPARATOR);
        interactableBlocks.add(Material.REPEATER);
        interactableBlocks.add(Material.LECTERN);
        interactableBlocks.add(Material.OAK_DOOR);
        interactableBlocks.add(Material.BIRCH_DOOR);
        interactableBlocks.add(Material.BAMBOO_DOOR);
        interactableBlocks.add(Material.DARK_OAK_DOOR);
        interactableBlocks.add(Material.SPRUCE_DOOR);
        interactableBlocks.add(Material.JUNGLE_DOOR);
        interactableBlocks.add(Material.ACACIA_DOOR);
        interactableBlocks.add(Material.OAK_TRAPDOOR);
        interactableBlocks.add(Material.BIRCH_TRAPDOOR);
        interactableBlocks.add(Material.BAMBOO_TRAPDOOR);
        interactableBlocks.add(Material.DARK_OAK_TRAPDOOR);
        interactableBlocks.add(Material.SPRUCE_TRAPDOOR);
        interactableBlocks.add(Material.JUNGLE_TRAPDOOR);
        interactableBlocks.add(Material.ACACIA_TRAPDOOR);
        interactableBlocks.add(Material.OAK_FENCE_GATE);
        interactableBlocks.add(Material.BIRCH_FENCE_GATE);
        interactableBlocks.add(Material.BAMBOO_FENCE_GATE);
        interactableBlocks.add(Material.DARK_OAK_FENCE_GATE);
        interactableBlocks.add(Material.SPRUCE_FENCE_GATE);
        interactableBlocks.add(Material.JUNGLE_FENCE_GATE);
        interactableBlocks.add(Material.ACACIA_FENCE_GATE);
        interactableBlocks.add(Material.CHEST_MINECART);
        interactableBlocks.add(Material.HOPPER_MINECART);
        interactableBlocks.add(Material.FURNACE_MINECART);
        interactableBlocks.add(Material.MINECART);
        interactableBlocks.add(Material.TNT_MINECART);
        interactableBlocks.add(Material.OAK_BOAT);
        interactableBlocks.add(Material.BIRCH_BOAT);
        interactableBlocks.add(Material.BAMBOO_RAFT);
        interactableBlocks.add(Material.DARK_OAK_BOAT);
        interactableBlocks.add(Material.SPRUCE_BOAT);
        interactableBlocks.add(Material.JUNGLE_BOAT);
        interactableBlocks.add(Material.ACACIA_BOAT);
        interactableBlocks.add(Material.OAK_CHEST_BOAT);
        interactableBlocks.add(Material.BIRCH_CHEST_BOAT);
        interactableBlocks.add(Material.BAMBOO_CHEST_RAFT);
        interactableBlocks.add(Material.DARK_OAK_CHEST_BOAT);
        interactableBlocks.add(Material.SPRUCE_CHEST_BOAT);
        interactableBlocks.add(Material.JUNGLE_CHEST_BOAT);
        interactableBlocks.add(Material.ACACIA_CHEST_BOAT);
        interactableBlocks.add(Material.ENCHANTING_TABLE);
        interactableBlocks.add(Material.RESPAWN_ANCHOR);
        interactableBlocks.add(Material.BREWING_STAND);
        interactableBlocks.add(Material.LECTERN);
        interactableBlocks.add(Material.WHITE_BED);
        interactableBlocks.add(Material.LIGHT_GRAY_BED);
        interactableBlocks.add(Material.GRAY_BED);
        interactableBlocks.add(Material.BLACK_BED);
        interactableBlocks.add(Material.BROWN_BED);
        interactableBlocks.add(Material.RED_BED);
        interactableBlocks.add(Material.ORANGE_BED);
        interactableBlocks.add(Material.YELLOW_BED);
        interactableBlocks.add(Material.LIME_BED);
        interactableBlocks.add(Material.GREEN_BED);
        interactableBlocks.add(Material.CYAN_BED);
        interactableBlocks.add(Material.LIGHT_BLUE_BED);
        interactableBlocks.add(Material.BLUE_BED);
        interactableBlocks.add(Material.PURPLE_BED);
        interactableBlocks.add(Material.MAGENTA_BED);
        interactableBlocks.add(Material.PINK_BED);
        interactableBlocks.add(Material.BELL);
        interactableBlocks.add(Material.CAKE);
        interactableBlocks.add(Material.JUKEBOX);
        interactableBlocks.add(Material.NOTE_BLOCK);
        interactableBlocks.add(Material.CANDLE);
        interactableBlocks.add(Material.COMPOSTER);
        interactableBlocks.add(Material.ITEM_FRAME);
        interactableBlocks.add(Material.GLOW_ITEM_FRAME);
        interactableBlocks.add(Material.ARMOR_STAND);
        interactableBlocks.add(Material.DRAGON_EGG);
        interactableBlocks.add(Material.BEACON);

        if (interactableBlocks.contains(b.getType())) {
            return true;
        } else {
            return false;
        }
    }

        public static String itemStackArrayToBase64(ItemStack[] itemArray) throws IllegalStateException {

        try {
            byte[] iss = ItemStack.serializeItemsAsBytes(itemArray);
            return Base64Coder.encodeLines(iss);
        } catch (Exception e) {
            throw new IllegalStateException("Error whilst saving items, Please contact the developer", e);
        }
    }

    public static ItemStack[] itemStackArrayFromBase64(String data) throws IOException {
        try {
            ItemStack[] is = ItemStack.deserializeItemsFromBytes(Base64Coder.decodeLines(data));
            return is;
        } catch (IllegalStateException e) {
            throw new IOException("Error whilst loading items, Please contact the developer", e);
        }

    }

}
