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.Vec3b;
import speiger.src.coreengine.math.vector.doubles.Vec3d;
import speiger.src.coreengine.math.vector.floats.Vec3f;
import speiger.src.coreengine.math.vector.longs.Vec3l;
import speiger.src.coreengine.math.vector.shorts.Vec3s;


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

	@Override
	public default Vec3i sub(int value){return sub(value, value, value);}
	public default Vec3i sub(Vec3i value){return sub(value.getX(), value.getY(), value.getZ());}
	public default Vec3i sub(int x, int y, int z){return set(getX() - x, getY() - y, getZ() - z);}
	
	@Override
	public default Vec3i multiply(int value){return multiply(value, value, value);}
	public default Vec3i multiply(Vec3i value){return multiply(value.getX(), value.getY(), value.getZ());}
	public default Vec3i multiply(int x, int y, int z){return set(getX() * x, getY() * y, getZ() * z);}

	@Override
	public default Vec3i devide(int value){return devide(value, value, value);}
	public default Vec3i devide(Vec3i value){return devide(value.getX(), value.getY(), value.getZ());}
	public default Vec3i devide(int x, int y, int z){return set(getX() / x, getY() / y, getZ() / z);}
	
	@Override
	public default Vec3i set(int value){return set(value, value, value);}
	public default Vec3i set(Vec3i value){return set(value.getX(), value.getY(), value.getZ());}
	public Vec3i set(int x, int y, int z);
	
	public default double distanceTo(Vec3i value){return distanceTo(value.getX(), value.getY(), value.getZ());}
	public default double distanceTo(int x, int y, int z){return Math.sqrt(distanceToSquared(x, y, z));}
	
	public default long distanceToSquared(Vec3i value){return distanceToSquared(value.getX(), value.getY(), value.getZ());}
	public default long distanceToSquared(int x, int y, int z)
	{
		long xPos = getX() - x;
		long yPos = getY() - y;
		long zPos = getZ() - z;
		return (xPos * xPos) + (yPos * yPos) + (zPos * zPos);
	}
	@Override
	public default long lengthSquared() {return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ());}
	
	public default long dotProduct(Vec3i value){return dotProduct(value.getX(), value.getY(), value.getZ());}
	public default long dotProduct(int x, int y, int z){return (getX() * x) + (getY() * y) + (getZ() * z);}
	
	public default Vec3i min(Vec3i other) {return min(other, this);}
	public default Vec3i min(Vec3i other, Vec3i result){return min(other.getX(), other.getY(), other.getZ(), result);}
	public default Vec3i min(int x, int y, int z) {return min(x, y, z, this);}
	public default Vec3i min(int x, int y, int z, Vec3i result){return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z));}
	
	public default Vec3i max(Vec3i other) {return max(other, this);}
	public default Vec3i max(Vec3i other, Vec3i result){return max(other.getX(), other.getY(), other.getZ(), result);}
	public default Vec3i max(int x, int y, int z) {return max(x, y, z, this);}
	public default Vec3i max(int x, int y, int z, Vec3i result){return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z));}
	
	public default Vec3i difference(Vec3i other) {return difference(other, this);}
	public default Vec3i difference(Vec3i other, Vec3i result){return difference(other.getX(), other.getY(), other.getZ(), result);}
	public default Vec3i difference(int x, int y, int z) {return difference(x, y, z, this);}
	public default Vec3i difference(int x, int y, int z, Vec3i result){return result.set(getX() - x, getY() - y, getZ() - z);}
	
	@Override
	public default Vec3i clamp(int min, int max){return clamp(min, max, ALL);}
	public default Vec3i clamp(int min, int max, Vec3i result){return clamp(min, max, result, ALL);}
	@Override
	public default Vec3i clamp(int min, int max, int filter){return clamp(min, max, this, filter);}
	public default Vec3i clamp(int min, int max, Vec3i 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()));}
	
	@Override
	public default Vec3i store(ByteBuffer buffer)
	{
		buffer.putInt(getX()).putInt(getY()).putInt(getZ());
		return this;
	}
	
	@Override
	public default Vec3i load(ByteBuffer buffer)
	{
		return set(buffer.getInt(), buffer.getInt(), buffer.getInt());
	}
	
	@Override
	public default Vec3i store(IntBuffer buffer)
	{
		buffer.put(getX()).put(getY()).put(getZ());
		return this;
	}
	
	@Override
	public default Vec3i load(IntBuffer buffer)
	{
		return set(buffer.get(), buffer.get(), buffer.get());
	}
	
	@Override
	public default Vec3b asByte(){return isMutable() ? Vec3b.newMutable((byte)getX(), (byte)getY(), (byte)getZ()) : Vec3b.newVec((byte)getX(), (byte)getY(), (byte)getZ());}
	@Override
	public default Vec3s asShort(){return isMutable() ? Vec3s.newMutable((short)getX(), (short)getY(), (short)getZ()) : Vec3s.newVec((short)getX(), (short)getY(), (short)getZ());}
	@Override
	public default Vec3l asLong(){return isMutable() ? Vec3l.newMutable(getX(), getY(), getZ()) : Vec3l.newVec(getX(), getY(), getZ());}
	@Override
	public default Vec3f asFloat() {return isMutable() ? Vec3f.newMutable(getX(), getY(), getZ()) : Vec3f.newVec(getX(), getY(), getZ());}
	@Override
	public default Vec3d asDouble(){return isMutable() ? Vec3d.newMutable(getX(), getY(), getZ()) : Vec3d.newVec(getX(), getY(), getZ());}

	
	@Override
	public default Vec3i asMutable(){return isMutable() ? this : newMutable(this);}
	@Override
	public default Vec3i asImmutable(){return isMutable() ? newVec(this) : this;}
	@Override
	public default Vec3i copyAsMutable(){return newMutable(this);}
	@Override
	public default Vec3i copyAsImmutable(){return newVec(this);}
}
