package protocolsupport.protocol.typeremapper.legacy;

import java.util.regex.Pattern;

import org.bukkit.NamespacedKey;

public class LegacyCustomPayloadChannelName {

	public static final String MODERN_REGISTER = "minecraft:register";
	public static final String MODERN_UNREGISTER = "minecraft:unregister";
	public static final String MODERN_TRADER_LIST = "minecraft:trader_list";
	public static final String MODERN_BRAND = "minecraft:brand";

	public static final String LEGACY_REGISTER = "REGISTER";
	public static final String LEGACY_UNREGISTER = "UNREGISTER";
	public static final String LEGACY_COMMAND_BLOCK_NAME = "MC|AutoCmd";
	public static final String LEGACY_COMMAND_RIGHT_NAME = "MC|AdvCmd";
	public static final String LEGACY_COMMAND_TYPO_NAME = "MC|AdvCdm";
	public static final String LEGACY_BOOK_EDIT = "MC|BEdit";
	public static final String LEGACY_BOOK_SIGN = "MC|BSign";
	public static final String LEGACY_SET_BEACON = "MC|Beacon";
	public static final String LEGACY_NAME_ITEM = "MC|ItemName";
	public static final String LEGACY_PICK_ITEM = "MC|PickItem";

	public static String toPre13(String modernName) {
		switch (modernName) {
			case MODERN_TRADER_LIST: {
				return "MC|TrList";
			}
			case MODERN_BRAND: {
				return "MC|Brand";
			}
			case "minecraft:book_open": {
				return "MC|BOpen";
			}
			case MODERN_REGISTER: {
				return LEGACY_REGISTER;
			}
			case MODERN_UNREGISTER: {
				return LEGACY_UNREGISTER;
			}
			default: {
				return modernName;
			}
		}
	}

	public static String fromPre13(String legacyName) {
		switch (legacyName) {
			case LEGACY_REGISTER: {
				return MODERN_REGISTER;
			}
			case LEGACY_UNREGISTER: {
				return MODERN_UNREGISTER;
			}
			case "MC|Brand": {
				return MODERN_BRAND;
			}
			default: {
				return fixPre13(legacyName);
			}
		}
	}

	private static final Pattern invalid_key_pattern = Pattern.compile("[^a-z0-9._-]+");

	@SuppressWarnings("deprecation")
	public static String fixPre13(String legacyName) {
		return new NamespacedKey("l", invalid_key_pattern.matcher(legacyName.toLowerCase()).replaceAll("")).toString();
	}

}

@@ -437,16 +437,83 @@
 :brand%22;
+%0A%09public static final String MODERN_BUNGEECORD = %22bungeecord:main%22;
 %0A%0A%09publi
@@ -1135,16 +1135,78 @@
 ckItem%22;
+%0A%09public static final String LEGACY_BUNGEECORD = %22BungeeCord%22;
 %0A%0A%09publi
@@ -1566,24 +1566,88 @@
 ISTER;%0A%09%09%09%7D%0A
+%09%09%09case MODERN_BUNGEECORD: %7B%0A%09%09%09%09return LEGACY_BUNGEECORD;%0A%09%09%09%7D%0A
 %09%09%09default: 
@@ -1929,32 +1929,96 @@
 ERN_BRAND;%0A%09%09%09%7D%0A
+%09%09%09case LEGACY_BUNGEECORD: %7B%0A%09%09%09%09return MODERN_BUNGEECORD;%0A%09%09%09%7D%0A
 %09%09%09default: %7B%0A%09%09
@@ -2068,13 +2068,15 @@
 %0A%09pr
-ivate
+otected
  sta

Transform bungeecord channel