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 = of();
	public static final Vec4l MINUS_ONE = of(-1L);
	public static final Vec4l ONE = of(1L);
	
	public static Vec4l mutable() { return new Vec4lMutable(); }
	public static Vec4l mutable(long value) { return new Vec4lMutable(value); }
	public static Vec4l mutable(long x, long y, long z, long w) { return new Vec4lMutable(x, y, z, w); }
	public static Vec4l mutable(Vec4l vec) { return mutable(vec.x(), vec.y(), vec.z(), vec.w()); }
	public static Vec4l of() { return new Vec4lImmutable(); }
	public static Vec4l of(long value) { return new Vec4lImmutable(value); }
	public static Vec4l of(long x, long y, long z, long w) { return new Vec4lImmutable(x, y, z, w); }
	public static Vec4l of(Vec4l vec) { return of(vec.x(), vec.y(), vec.z(), vec.w()); }
	
	public long x();
	public long y();
	public long z();
	public long w();
	public Vec4l x(long x);
	public Vec4l y(long y);
	public Vec4l z(long z);
	public Vec4l w(long w);
	
	@Override
	public default long[] asArray() { return new long[] {x(), y(), z(), w()}; }
	@Override
	public Vec4l copy();
	@Override
	public default Vec4l abs() { return set(Math.abs(x()), Math.abs(y()), Math.abs(z()), Math.abs(w())); }
	@Override
	public default Vec4l negate() { return set(0L, 0L, 0L, 0L); }
	@Override
	public default Vec4l invert() { return set(-x(), -y(), -z(), -w()); }
	@Override
	public default Vec4l add(long value) { return add(value, value, value, value); }
	public default Vec4l add(Vec4l value) { return add(value.x(), value.y(), value.z(), value.w()); }
	public default Vec4l add(long x, long y, long z, long w) { return set(x() + x, y() + y, z() + z, w() + w); }
	@Override
	public default Vec4l sub(long value) { return sub(value, value, value, value); }
	public default Vec4l sub(Vec4l value) { return sub(value.x(), value.y(), value.z(), value.w()); }
	public default Vec4l sub(long x, long y, long z, long w) { return set(x() - x, y() - y, z() - z, w() - w); }
	@Override
	public default Vec4l multiply(long value) { return multiply(value, value, value, value); }
	public default Vec4l multiply(Vec4l value) { return multiply(value.x(), value.y(), value.z(), value.w()); }
	public default Vec4l multiply(long x, long y, long z, long w) { return set(x() * x, y() * y, z() * z, w() * w); }
	@Override
	public default Vec4l devide(long value) { return devide(value, value, value, value); }
	public default Vec4l devide(Vec4l value) { return devide(value.x(), value.y(), value.z(), value.w()); }
	public default Vec4l devide(long x, long y, long z, long w) { return set(x() / x, y() / y, z() / z, w() / w); }
	@Override
	public default Vec4l set(long value) { return set(value, value, value, value); }
	public default Vec4l set(Vec4l value) { return set(value.x(), value.y(), value.z(), value.w()); }
	public Vec4l set(long x, long y, long z, long w);
	public default double distanceTo(Vec4l value) { return distanceTo(value.x(), value.y(), value.z(), value.w()); }
	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.x(), value.y(), value.z(), value.w()); }
	public default long distanceToSquared(long x, long y, long z, long w) {
		long xPos = x() - x;
		long yPos = y() - y;
		long zPos = z() - z;
		long wPos = w() - w;
		return (xPos * xPos) + (yPos * yPos) + (zPos * zPos) + (wPos * wPos);
	}
	
	@Override
	public default long lengthSquared() { return (x() * x()) + (y() * y()) + (z() * z()) + (w() * w()); }
	public default long dotProduct(Vec4l value) { return dotProduct(value.x(), value.y(), value.z(), value.w()); }
	public default long dotProduct(long x, long y, long z, long w) { return (x() * x) + (y() * y) + (z() * z) + (w() * w); };
	public default Vec4l min(Vec4l other) { return min(other, this); }
	public default Vec4l min(Vec4l other, Vec4l result) { return min(other.x(), other.y(), other.z(), other.w(), 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(x(), x), Math.min(y(), y), Math.min(z(), z), Math.min(w(), w)); }
	public default Vec4l max(Vec4l other) { return max(other, this); }
	public default Vec4l max(Vec4l other, Vec4l result) { return max(other.x(), other.y(), other.z(), other.w(), 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(x(), x), Math.max(y(), y), Math.max(z(), z), Math.max(z(), z)); }
	public default Vec4l difference(Vec4l other) { return difference(other, this); }
	public default Vec4l difference(Vec4l other, Vec4l result) { return difference(other.x(), other.y(), other.z(), other.w(), 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(x() - x, y() - y, z() - z, w() - 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 ? x() : MathUtils.clamp(min, max, x()), (filter & Y) == 0 ? y() : MathUtils.clamp(min, max, y()), (filter & Z) == 0 ? z() : MathUtils.clamp(min, max, z()), (filter & W) == 0 ? w() : MathUtils.clamp(min, max, w())); }
	
	@Override
	public default Vec4l store(ByteBuffer buffer) {
		buffer.putLong(x()).putLong(y()).putLong(z()).putLong(w());
		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(x()).put(y()).put(z()).put(w());
		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.mutable((byte)x(), (byte)y(), (byte)z(), (byte)w()) : Vec4b.of((byte)x(), (byte)y(), (byte)z(), (byte)w()); }
	@Override
	public default Vec4s asShort() { return isMutable() ? Vec4s.mutable((short)x(), (short)y(), (short)z(), (short)w()) : Vec4s.of((short)x(), (short)y(), (short)z(), (short)w()); }
	@Override
	public default Vec4i asInt() { return isMutable() ? Vec4i.mutable((int)x(), (int)y(), (int)z(), (int)w()) : Vec4i.of((int)x(), (int)y(), (int)z(), (int)w()); }
	@Override
	public default Vec4f asFloat() { return isMutable() ? Vec4f.mutable(x(), y(), z(), w()) : Vec4f.of(x(), y(), z(), w()); }
	@Override
	public default Vec4d asDouble() { return isMutable() ? Vec4d.mutable(x(), y(), z(), w()) : Vec4d.of(x(), y(), z(), w()); }
	@Override
	public default Vec4l asMutable() { return isMutable() ? this : mutable(this); }
	@Override
	public default Vec4l asImmutable() { return isMutable() ? of(this) : this; }
	@Override
	public default Vec4l copyAsMutable() { return mutable(this); }
	@Override
	public default Vec4l copyAsImmutable() { return of(this); }
}
