package protocolsupport.protocol.typeremapper.entity;

import javax.annotation.Nonnull;

import protocolsupport.protocol.codec.NetworkEntityMetadataSerializer.NetworkEntityMetadataList;
import protocolsupport.protocol.typeremapper.entity.format.NetworkEntityLegacyFormatRegistry.NetworkEntityLegacyFormatTable;
import protocolsupport.protocol.typeremapper.entity.format.metadata.object.NetworkEntityMetadataFormatTransformer;
import protocolsupport.protocol.typeremapper.entity.legacy.NetworkEntityLegacyDataRegistry.NetworkEntityLegacyDataEntry;
import protocolsupport.protocol.typeremapper.entity.legacy.NetworkEntityLegacyDataRegistry.NetworkEntityLegacyDataTable;
import protocolsupport.protocol.types.networkentity.NetworkEntity;
import protocolsupport.protocol.types.networkentity.NetworkEntityType;
import protocolsupport.protocol.types.networkentity.metadata.NetworkEntityMetadataObject;
import protocolsupport.utils.CollectionsUtils.ArrayMap;

public class NetworkEntityTransformHelper {

	private NetworkEntityTransformHelper() {
	}

	public static NetworkEntityType transformTypeFormat(NetworkEntityType type, NetworkEntityLegacyDataTable dataTable, NetworkEntityLegacyFormatTable formatTable) {
		return formatTable.get(dataTable.get(type).getType()).getType();
	}

	public static void transformMetadata(
		@Nonnull NetworkEntity entity, @Nonnull ArrayMap<NetworkEntityMetadataObject<?>> metadata,
		@Nonnull NetworkEntityLegacyDataEntry entityLegacyDataTable, @Nonnull NetworkEntityLegacyFormatTable entityLegacyFormatTable,
		@Nonnull NetworkEntityMetadataList legacyFormatMetadata
	) {
		entityLegacyDataTable.transformMetadata(metadata);
		transformMetadataFormat(entity, entityLegacyDataTable.getType(), metadata, entityLegacyFormatTable, legacyFormatMetadata);
	}

	public static void transformMetadataFormat(
		@Nonnull NetworkEntity entity, @Nonnull NetworkEntityType type, @Nonnull ArrayMap<NetworkEntityMetadataObject<?>> metadata,
		@Nonnull NetworkEntityLegacyFormatTable entityLegacyFormatTable,
		@Nonnull NetworkEntityMetadataList fMetadata
	) {
		for (NetworkEntityMetadataFormatTransformer fMetadataTransformer : entityLegacyFormatTable.get(type).getMetadataTransformers()) {
			fMetadataTransformer.transform(entity, metadata, fMetadata);
		}
		entity.getDataCache().unsetFirstMeta();
	}

}

@@ -1052,16 +1052,25 @@
  static 
+@Nonnull 
 NetworkE
@@ -1099,16 +1099,28 @@
 eFormat(
+%0A%09%09@Nonnull 
 NetworkE
@@ -1134,16 +1134,27 @@
 pe type,
+%0A%09%09@Nonnull
  Network
@@ -1185,16 +1185,25 @@
 taTable,
+ @Nonnull
  Network
@@ -1241,27 +1241,46 @@
 able
+%0A%09
 ) %7B%0A%09%09
-return form
+NetworkEntityType lType = d
 at
+a
 Tabl
@@ -1289,37 +1289,134 @@
 get(
-dataTable.get(type)
+type).getType();%0A%09%09if (lType == NetworkEntityType.NONE) %7B%0A%09%09%09return NetworkEntityType.NONE;%0A%09%09%7D%0A%09%09return formatTable
 .get
+(l
 Type
-()
 ).ge

Make NetworkEntityTransformHelper#transformTypeFormat return NetworkEntityType#NONE if entity legacy data type is NONE instead of throwng an error