package client.renderer;

import org.lwjgl.opengl.GL11;

public record VertexFormatElement(int index, VertexFormatElement.EnumType type, VertexFormatElement.EnumUsage usage, int count) {
	public String toString() {
		return this.count + "," + this.usage.getName() + "," + this.type.getName();
	}

	public int size() {
		return this.type.getSize() * this.count;
	}

	public boolean isPosition() {
		return this.usage == VertexFormatElement.EnumUsage.POSITION;
	}

	public boolean equals(Object other) {
		if(this == other)
			return true;
		if(!(other instanceof VertexFormatElement))
			return false;
		VertexFormatElement elem = (VertexFormatElement)other;
		return this.count == elem.count && this.index == elem.index && this.type == elem.type && this.usage == elem.usage;
	}

	public int hashCode() {
		int i = this.type.hashCode();
		i = 31 * i + this.usage.hashCode();
		i = 31 * i + this.index;
		i = 31 * i + this.count;
		return i;
	}

	public static enum EnumType {
		FLOAT(4, "Float", GL11.GL_FLOAT),
		UBYTE(1, "Unsigned Byte", GL11.GL_UNSIGNED_BYTE),
		BYTE(1, "Byte", GL11.GL_BYTE),
		USHORT(2, "Unsigned Short", GL11.GL_UNSIGNED_SHORT),
		SHORT(2, "Short", GL11.GL_SHORT),
		UINT(4, "Unsigned Int", GL11.GL_UNSIGNED_INT),
		INT(4, "Int", GL11.GL_INT);

		private final int size;
		private final String name;
		private final int glConstant;

		private EnumType(int size, String name, int glConstant) {
			this.size = size;
			this.name = name;
			this.glConstant = glConstant;
		}

		public int getSize() {
			return this.size;
		}

		public String getName() {
			return this.name;
		}

		public int getGlConstant() {
			return this.glConstant;
		}
	}

	public static enum EnumUsage {
		POSITION("Position"),
		NORMAL("Normal"),
		COLOR("Vertex Color"),
		UV("UV"),
		PADDING("Padding");

		private final String name;

		private EnumUsage(String name) {
			this.name = name;
		}

		public String getName() {
			return this.name;
		}
	}
}
