package speiger.src.coreengine.math.vector.ints;

import java.nio.ByteBuffer;
import java.nio.IntBuffer;

import speiger.src.coreengine.math.MathUtils;
import speiger.src.coreengine.math.vector.bytes.Vec4b;
import speiger.src.coreengine.math.vector.doubles.Vec4d;
import speiger.src.coreengine.math.vector.floats.Vec4f;
import speiger.src.coreengine.math.vector.longs.Vec4l;
import speiger.src.coreengine.math.vector.shorts.Vec4s;

public interface Vec4i extends Veci
{
	public static final Vec4i ZERO = newVec();
	public static final Vec4i MINUS_ONE = newVec(-1);
	public static final Vec4i ONE = newVec(1);
	
	public static Vec4i newMutable(){return new Vec4iMutable();}
	public static Vec4i newMutable(int value){return new Vec4iMutable(value);}
	public static Vec4i newMutable(int x, int y, int z, int w){return new Vec4iMutable(x, y, z, w);}
	public static Vec4i newMutable(Vec4i vec){return newMutable(vec.getX(), vec.getY(), vec.getZ(), vec.getW());}
	
	public static Vec4i newVec(){return new Vec4iImmutable();}
	public static Vec4i newVec(int value){return new Vec4iImmutable(value);}
	public static Vec4i newVec(int x, int y, int z, int w){return new Vec4iImmutable(x, y, z, w);}
	public static Vec4i newVec(Vec4i vec){return newVec(vec.getX(), vec.getY(), vec.getZ(), vec.getW());}
	
	public int getX();
	public int getY();
	public int getZ();
	public int getW();
	public Vec4i setX(int x);
	public Vec4i setY(int y);
	public Vec4i setZ(int z);
	public Vec4i setW(int w);
	@Override
	public default int[] asArray(){return new int[]{getX(), getY(), getZ(), getW()};}
	@Override
	public Vec4i copy();
	@Override
	public default Vec4i abs(){return set(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ()), Math.abs(getW()));}
	@Override
	public default Vec4i negate(){return set(0, 0, 0, 0);}
	@Override
	public default Vec4i invert(){return set(-getX(), -getY(), -getZ(), -getW());}
	
	@Override
	public default Vec4i add(int value){return add(value, value, value, value);}	
	public default Vec4i add(Vec4i value){return add(value.getX(), value.getY(), value.getZ(), value.getW());}
	public default Vec4i add(int x, int y, int z, int w){return set(getX() + x, getY() + y, getZ() + z, getW() + w);}

	@Override
	public default Vec4i sub(int value){return sub(value, value, value, value);}
	public default Vec4i sub(Vec4i value){return sub(value.getX(), value.getY(), value.getZ(), value.getW());}
	public default Vec4i sub(int x, int y, int z, int w){return set(getX() - x, getY() - y, getZ() - z, getW() - w);}
	
	@Override
	public default Vec4i multiply(int value){return multiply(value, value, value, value);}
	public default Vec4i multiply(Vec4i value){return multiply(value.getX(), value.getY(), value.getZ(), value.getW());}
	public default Vec4i multiply(int x, int y, int z, int w){return set(getX() * x, getY() * y, getZ() * z, getW() * w);}
	
	@Override
	public default Vec4i devide(int value){return devide(value, value, value, value);}
	public default Vec4i devide(Vec4i value){return devide(value.getX(), value.getY(), value.getZ(), value.getW());}
	public default Vec4i devide(int x, int y, int z, int w){return set(getX() / x, getY() / y, getZ() / z, getW() / w);}
	
	@Override
	public default Vec4i set(int value){return set(value, value, value, value);}
	public default Vec4i set(Vec4i value){return set(value.getX(), value.getY(), value.getZ(), value.getW());}
	public Vec4i set(int x, int y, int z, int w);
	
	public default double distanceTo(Vec4i value){return distanceTo(value.getX(), value.getY(), value.getZ(), value.getW());}
	public default double distanceTo(int x, int y, int z, int w){return Math.sqrt(distanceTo(x, y, z, w));}
	
	public default long distanceToSquared(Vec4i value){return distanceToSquared(value.getX(), value.getY(), value.getZ(), value.getW());}
	public default long distanceToSquared(int x, int y, int z, int w)
	{
		long xPos = getX() - x;
		long yPos = getY() - y;
		long zPos = getZ() - z;
		long wPos = getW() - w;
		return (xPos * xPos) + (yPos * yPos) + (zPos * zPos) + (wPos * wPos);
	}
	@Override
	public default long lengthSquared() {return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()) + (getW() * getW());}

	public default long dotProduct(Vec4i value){return dotProduct(value.getX(), value.getY(), value.getZ(), value.getW());}
	public default long dotProduct(int x, int y, int z, int w){return (getX() * x) + (getY() * y) + (getZ() * z) + (getW() * w);};
	
	public default Vec4i min(Vec4i other) {return min(other, this);}
	public default Vec4i min(Vec4i other, Vec4i result){return min(other.getX(), other.getY(), other.getZ(), other.getW(), result);}
	public default Vec4i min(int x, int y, int z, int w) {return min(x, y, z, w, this);}
	public default Vec4i min(int x, int y, int z, int w, Vec4i result){return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z), Math.min(getW(), w));}
	
	public default Vec4i max(Vec4i other) {return max(other, this);}
	public default Vec4i max(Vec4i other, Vec4i result){return max(other.getX(), other.getY(), other.getZ(), other.getW(), result);}
	public default Vec4i max(int x, int y, int z, int w) {return max(x, y, z, w, this);}
	public default Vec4i max(int x, int y, int z, int w, Vec4i result){return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z), Math.max(getZ(), z));}
	
	public default Vec4i difference(Vec4i other) {return difference(other, this);}
	public default Vec4i difference(Vec4i other, Vec4i result){return difference(other.getX(), other.getY(), other.getZ(), other.getW(), result);}
	public default Vec4i difference(int x, int y, int z, int w) {return difference(x, y, z, w, this);}
	public default Vec4i difference(int x, int y, int z, int w, Vec4i result){return result.set(getX() - x, getY() - y, getZ() - z, getW() - w);}
	
	@Override
	public default Vec4i clamp(int min, int max){return clamp(min, max, ALL);}
	public default Vec4i clamp(int min, int max, Vec4i result){return clamp(min, max, result, ALL);}
	@Override
	public default Vec4i clamp(int min, int max, int filter){return clamp(min, max, this, filter);}
	public default Vec4i clamp(int min, int max, Vec4i result, int filter){ return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()), (filter & W) == 0 ? getW() : MathUtils.clamp(min, max, getW()));}
	
	@Override
	public default Vec4i store(ByteBuffer buffer)
	{
		buffer.putInt(getX()).putInt(getY()).putInt(getZ()).putInt(getW());
		return this;
	}
	
	@Override
	public default Vec4i load(ByteBuffer buffer)
	{
		return set(buffer.getInt(), buffer.getInt(), buffer.getInt(), buffer.getInt());
	}
	
	@Override
	public default Vec4i store(IntBuffer buffer)
	{
		buffer.put(getX()).put(getY()).put(getZ()).put(getW());
		return this;
	}
	
	@Override
	public default Vec4i load(IntBuffer buffer)
	{
		return set(buffer.get(), buffer.get(), buffer.get(), buffer.get());
	}
	
	@Override
	public default Vec4b asByte(){return isMutable() ? Vec4b.newMutable((byte)getX(), (byte)getY(), (byte)getZ(), (byte)getW()) : Vec4b.newVec((byte)getX(), (byte)getY(), (byte)getZ(), (byte)getW());}
	@Override
	public default Vec4s asShort(){return isMutable() ? Vec4s.newMutable((short)getX(), (short)getY(), (short)getZ(), (short)getW()) : Vec4s.newVec((short)getX(), (short)getY(), (short)getZ(), (short)getW());}
	@Override
	public default Vec4l asLong(){return isMutable() ? Vec4l.newMutable(getX(), getY(), getZ(), getW()) : Vec4l.newVec(getX(), getY(), getZ(), getW());}
	@Override
	public default Vec4f asFloat() {return isMutable() ? Vec4f.newMutable(getX(), getY(), getZ(), getW()) : Vec4f.newVec(getX(), getY(), getZ(), getW());}
	@Override
	public default Vec4d asDouble(){return isMutable() ? Vec4d.newMutable(getX(), getY(), getZ(), getW()) : Vec4d.newVec(getX(), getY(), getZ(), getW());}
	
	@Override
	public default Vec4i asMutable(){return isMutable() ? this : newMutable(this);}
	@Override
	public default Vec4i asImmutable(){return isMutable() ? newVec(this) : this;}
	@Override
	public default Vec4i copyAsMutable(){return newMutable(this);}
	@Override
	public default Vec4i copyAsImmutable(){return newVec(this);}
}
