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

import java.nio.ByteBuffer;
import java.nio.LongBuffer;

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.ints.Vec3i;
import speiger.src.coreengine.math.vector.shorts.Vec3s;


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

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

	@Override
	public default Vec3l devide(long value){return devide(value, value, value);}
	public default Vec3l devide(Vec3l value){return devide(value.getX(), value.getY(), value.getZ());}
	public default Vec3l devide(long x, long y, long z){return set(getX() / x, getY() / y, getZ() / z);}
	
	@Override
	public default Vec3l set(long value){return set(value, value, value);}
	public default Vec3l set(Vec3l value){return set(value.getX(), value.getY(), value.getZ());}
	public Vec3l set(long x, long y, long z);
	
	public default double distanceTo(Vec3l value){return distanceTo(value.getX(), value.getY(), value.getZ());}
	public default double distanceTo(long x, long y, long z){return Math.sqrt(distanceToSquared(x, y, z));}
	
	public default long distanceToSquared(Vec3l value){return distanceToSquared(value.getX(), value.getY(), value.getZ());}
	public default long distanceToSquared(long x, long y, long 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(Vec3l value){return dotProduct(value.getX(), value.getY(), value.getZ());}
	public default long dotProduct(long x, long y, long z){return (getX() * x) + (getY() * y) + (getZ() * z);}
	
	public default Vec3l min(Vec3l other) {return min(other, this);}
	public default Vec3l min(Vec3l other, Vec3l result){return min(other.getX(), other.getY(), other.getZ(), result);}
	public default Vec3l min(long x, long y, long z) {return min(x, y, z, this);}
	public default Vec3l min(long x, long y, long z, Vec3l result){return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z));}
	
	public default Vec3l max(Vec3l other) {return max(other, this);}
	public default Vec3l max(Vec3l other, Vec3l result){return max(other.getX(), other.getY(), other.getZ(), result);}
	public default Vec3l max(long x, long y, long z) {return max(x, y, z, this);}
	public default Vec3l max(long x, long y, long z, Vec3l result){return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z));}
	
	public default Vec3l difference(Vec3l other) {return difference(other, this);}
	public default Vec3l difference(Vec3l other, Vec3l result){return difference(other.getX(), other.getY(), other.getZ(), result);}
	public default Vec3l difference(long x, long y, long z) {return difference(x, y, z, this);}
	public default Vec3l difference(long x, long y, long z, Vec3l result){return result.set(getX() - x, getY() - y, getZ() - z);}
	
	@Override
	public default Vec3l clamp(long min, long max){return clamp(min, max, ALL);}
	public default Vec3l clamp(long min, long max, Vec3l result){return clamp(min, max, result, ALL);}
	@Override
	public default Vec3l clamp(long min, long max, int filter){return clamp(min, max, this, filter);}
	public default Vec3l clamp(long min, long max, Vec3l 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 Vec3l store(ByteBuffer buffer)
	{
		buffer.putLong(getX()).putLong(getY()).putLong(getZ());
		return this;
	}
	
	@Override
	public default Vec3l load(ByteBuffer buffer)
	{
		return set(buffer.getLong(), buffer.getLong(), buffer.getLong());
	}
	
	@Override
	public default Vec3l store(LongBuffer buffer)
	{
		buffer.put(getX()).put(getY()).put(getZ());
		return this;
	}
	
	@Override
	public default Vec3l load(LongBuffer 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 Vec3i asInt(){return isMutable() ? Vec3i.newMutable((int)getX(), (int)getY(), (int)getZ()) : Vec3i.newVec((int)getX(), (int)getY(), (int)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 Vec3l asMutable(){return isMutable() ? this : newMutable(this);}
	@Override
	public default Vec3l asImmutable(){return isMutable() ? newVec(this) : this;}
	@Override
	public default Vec3l copyAsMutable(){return newMutable(this);}
	@Override
	public default Vec3l copyAsImmutable(){return newVec(this);}
}
