package org.inventivetalent.nbt;

import com.google.gson.JsonElement;
import com.google.gson.JsonNull;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.inventivetalent.nbt.stream.NBTOutputStream;

import java.io.DataOutputStream;
import java.io.IOException;
import java.lang.reflect.Field;

@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class EndTag extends NBTTag<Void> {

	public EndTag() {
		this("");
	}

	public EndTag(String name) {
		super(name);
	}

	@Override
	public Void getValue() {
		return null;
	}

	@Override
	public JsonElement asJson() {
		return JsonNull.INSTANCE;
	}

	@Override
	public void write(NBTOutputStream nbtOut, DataOutputStream out) throws IOException {
	}

	@Override
	public int getTypeId() {
		return TagID.TAG_END;
	}

	@Override
	public String getTypeName() {
		return "TAG_End";
	}

	@Override
	public String getNMSClass() {
		return "NBTTagEnd";
	}

	public NBTTag fromNMS(Object nms) throws ReflectiveOperationException {
		Class<?> clazz = NMS_CLASS_RESOLVER.resolve(getNMSClass());
		Field field = clazz.getDeclaredField("data");
		return (NBTTag) getClass().getConstructors()[0].newInstance("", field.get(nms));
	}

	public Object toNMS() throws ReflectiveOperationException {
		Class<?> clazz = NMS_CLASS_RESOLVER.resolve(getNMSClass());
		return clazz.getConstructors()[0].newInstance(getValue());
	}
}

@@ -293,40 +293,8 @@
 ion;
-%0Aimport java.lang.reflect.Field;
 %0A%0A@D
@@ -999,196 +999,26 @@
 %7B%0A%09%09
-Class%3C?%3E clazz = NMS_CLASS_RESOLVER.resolve(getNMSClass());%0A%09%09Field field = clazz.getDeclaredField(%22data%22);%0A%09%09return (NBTTag) getClass().getConstructors()%5B0%5D.newInstance(%22%22, field.get(nms)
+return new EndTag(
 );%0A%09
@@ -1162,29 +1162,8 @@
 azz.
-getConstructors()%5B0%5D.
 newI
@@ -1170,26 +1170,16 @@
 nstance(
-getValue()
 );%0A%09%7D%0A%7D%0A

fix EndTag to/from NMS