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.Vec4b;
import speiger.src.coreengine.math.vector.doubles.Vec4d;
import speiger.src.coreengine.math.vector.floats.Vec4f;
import speiger.src.coreengine.math.vector.ints.Vec4i;
import speiger.src.coreengine.math.vector.shorts.Vec4s;

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

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