/**
 *
 */
package cn.citycraft.GsonAgent.nms;

import java.math.BigDecimal;
import java.math.BigInteger;

import cn.citycraft.GsonAgent.api.JsonPrimitive;
import cn.citycraft.GsonAgent.api.utils.Utils;

/**
 *
 * @since 2016年1月5日 下午1:49:49
 * @author 喵♂呜
 */
public class JsonPrimitiveHandle extends JsonElementHandle implements JsonPrimitive {

	private final net.minecraft.util.com.google.gson.JsonPrimitive handle;

	public JsonPrimitiveHandle(final Boolean bool) {
		this(new net.minecraft.util.com.google.gson.JsonPrimitive(bool));
		setValue(bool);
	}

	public JsonPrimitiveHandle(final Character c) {
		this(new net.minecraft.util.com.google.gson.JsonPrimitive(c));
		setValue(c);
	}

	public JsonPrimitiveHandle(final Number number) {
		this(new net.minecraft.util.com.google.gson.JsonPrimitive(number));
		setValue(number);
	}

	public JsonPrimitiveHandle(final String string) {
		this(new net.minecraft.util.com.google.gson.JsonPrimitive(string));
		setValue(string);
	}

	protected JsonPrimitiveHandle(final net.minecraft.util.com.google.gson.JsonPrimitive handle) {
		this.handle = handle;
	}

	@Override
	public cn.citycraft.GsonAgent.api.JsonPrimitive deepCopy() {
		return new JsonPrimitiveHandle(Utils.deepCopyObject(this.handle));
	}

	@Override
	public boolean equals(final Object obj) {
		return handle.equals(obj);
	}

	@Override
	public BigDecimal getAsBigDecimal() {
		return handle.getAsBigDecimal();
	}

	@Override
	public BigInteger getAsBigInteger() {
		return handle.getAsBigInteger();
	}

	@Override
	public boolean getAsBoolean() {
		return handle.getAsBoolean();
	}

	@Override
	public byte getAsByte() {
		return handle.getAsByte();
	}

	@Override
	public char getAsCharacter() {
		return handle.getAsCharacter();
	}

	@Override
	public double getAsDouble() {
		return handle.getAsDouble();
	}

	@Override
	public float getAsFloat() {
		return handle.getAsFloat();
	}

	@Override
	public int getAsInt() {
		return handle.getAsInt();
	}

	@Override
	public JsonArrayHandle getAsJsonArray() {
		return new JsonArrayHandle(handle.getAsJsonArray());
	}

	@Override
	public JsonObjectHandle getAsJsonObject() {
		return new JsonObjectHandle(handle.getAsJsonObject());
	}

	@Override
	public long getAsLong() {
		return handle.getAsLong();
	}

	@Override
	public Number getAsNumber() {
		return handle.getAsNumber();
	}

	@Override
	public short getAsShort() {
		return handle.getAsShort();
	}

	@Override
	public String getAsString() {
		return handle.getAsString();
	}

	@Override
	public int hashCode() {
		return handle.hashCode();
	}

	@Override
	public boolean isBoolean() {
		return handle.isBoolean();
	}

	@Override
	public boolean isNumber() {
		return handle.isNumber();
	}

	@Override
	public boolean isString() {
		return handle.isString();
	}

	@Override
	public final void setValue(final Object primitive) {
		try {
			handle.getClass().getDeclaredMethod("setValue", Object.class).invoke(handle, primitive);
		} catch (final Exception e) {
			throw new RuntimeException(e);
		}
	}

}
