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 = of();
	public static final Vec4i MINUS_ONE = of(-1);
	public static final Vec4i ONE = of(1);
	
	public static Vec4i mutable() { return new Vec4iMutable(); }
	public static Vec4i mutable(int value) { return new Vec4iMutable(value); }
	public static Vec4i mutable(int x, int y, int z, int w) { return new Vec4iMutable(x, y, z, w); }
	public static Vec4i mutable(Vec4i vec) { return mutable(vec.x(), vec.y(), vec.z(), vec.w()); }
	public static Vec4i of() { return new Vec4iImmutable(); }
	public static Vec4i of(int value) { return new Vec4iImmutable(value); }
	public static Vec4i of(int x, int y, int z, int w) { return new Vec4iImmutable(x, y, z, w); }
	public static Vec4i of(Vec4i vec) { return of(vec.x(), vec.y(), vec.z(), vec.w()); }
	
	public int x();
	public int y();
	public int z();
	public int w();
	public Vec4i x(int x);
	public Vec4i y(int y);
	public Vec4i z(int z);
	public Vec4i w(int w);
	
	@Override
	public default int[] asArray() { return new int[] {x(), y(), z(), w()}; }
	@Override
	public Vec4i copy();
	@Override
	public default Vec4i abs() { return set(Math.abs(x()), Math.abs(y()), Math.abs(z()), Math.abs(w())); }
	@Override
	public default Vec4i negate() { return set(0, 0, 0, 0); }
	@Override
	public default Vec4i invert() { return set(-x(), -y(), -z(), -w()); }
	@Override
	public default Vec4i add(int value) { return add(value, value, value, value); }
	public default Vec4i add(Vec4i value) { return add(value.x(), value.y(), value.z(), value.w()); }
	public default Vec4i add(int x, int y, int z, int w) { return set(x() + x, y() + y, z() + z, w() + w); }
	@Override
	public default Vec4i sub(int value) { return sub(value, value, value, value); }
	public default Vec4i sub(Vec4i value) { return sub(value.x(), value.y(), value.z(), value.w()); }
	public default Vec4i sub(int x, int y, int z, int w) { return set(x() - x, y() - y, z() - z, w() - w); }
	@Override
	public default Vec4i multiply(int value) { return multiply(value, value, value, value); }
	public default Vec4i multiply(Vec4i value) { return multiply(value.x(), value.y(), value.z(), value.w()); }
	public default Vec4i multiply(int x, int y, int z, int w) { return set(x() * x, y() * y, z() * z, w() * w); }
	@Override
	public default Vec4i devide(int value) { return devide(value, value, value, value); }
	public default Vec4i devide(Vec4i value) { return devide(value.x(), value.y(), value.z(), value.w()); }
	public default Vec4i devide(int x, int y, int z, int w) { return set(x() / x, y() / y, z() / z, w() / w); }
	@Override
	public default Vec4i set(int value) { return set(value, value, value, value); }
	public default Vec4i set(Vec4i value) { return set(value.x(), value.y(), value.z(), value.w()); }
	public Vec4i set(int x, int y, int z, int w);
	public default double distanceTo(Vec4i value) { return distanceTo(value.x(), value.y(), value.z(), value.w()); }
	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.x(), value.y(), value.z(), value.w()); }
	public default long distanceToSquared(int x, int y, int z, int 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(Vec4i value) { return dotProduct(value.x(), value.y(), value.z(), value.w()); }
	public default long dotProduct(int x, int y, int z, int w) { return (x() * x) + (y() * y) + (z() * z) + (w() * w); };
	public default Vec4i min(Vec4i other) { return min(other, this); }
	public default Vec4i min(Vec4i other, Vec4i result) { return min(other.x(), other.y(), other.z(), other.w(), 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(x(), x), Math.min(y(), y), Math.min(z(), z), Math.min(w(), w)); }
	public default Vec4i max(Vec4i other) { return max(other, this); }
	public default Vec4i max(Vec4i other, Vec4i result) { return max(other.x(), other.y(), other.z(), other.w(), 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(x(), x), Math.max(y(), y), Math.max(z(), z), Math.max(z(), z)); }
	public default Vec4i difference(Vec4i other) { return difference(other, this); }
	public default Vec4i difference(Vec4i other, Vec4i result) { return difference(other.x(), other.y(), other.z(), other.w(), 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(x() - x, y() - y, z() - z, w() - 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 ? 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 Vec4i store(ByteBuffer buffer) {
		buffer.putInt(x()).putInt(y()).putInt(z()).putInt(w());
		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(x()).put(y()).put(z()).put(w());
		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.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 Vec4l asLong() { return isMutable() ? Vec4l.mutable(x(), y(), z(), w()) : Vec4l.of(x(), y(), z(), 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 Vec4i asMutable() { return isMutable() ? this : mutable(this); }
	@Override
	public default Vec4i asImmutable() { return isMutable() ? of(this) : this; }
	@Override
	public default Vec4i copyAsMutable() { return mutable(this); }
	@Override
	public default Vec4i copyAsImmutable() { return of(this); }
}
