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 = of();
	public static final Vec3i MINUS_ONE = of(-1);
	public static final Vec3i ONE = of(1);
	
	public static Vec3i mutable() { return new Vec3iMutable(); }
	public static Vec3i mutable(int value) { return new Vec3iMutable(value); }
	public static Vec3i mutable(int x, int y, int z) { return new Vec3iMutable(x, y, z); }
	public static Vec3i mutable(Vec3i vec) { return mutable(vec.x(), vec.y(), vec.z()); }
	public static Vec3i of() { return new Vec3iImmutable(); }
	public static Vec3i of(int value) { return new Vec3iImmutable(value); }
	public static Vec3i of(int x, int y, int z) { return new Vec3iImmutable(x, y, z); }
	public static Vec3i of(Vec3i vec) { return of(vec.x(), vec.y(), vec.z()); }
	
	public int x();
	public int y();
	public int z();
	public Vec3i x(int x);
	public Vec3i y(int y);
	public Vec3i z(int z);
	
	@Override
	public default int[] asArray() { return new int[] {x(), y(), z()}; }
	@Override
	public Vec3i copy();
	@Override
	public default Vec3i abs() { return set(Math.abs(x()), Math.abs(y()), Math.abs(z())); }
	@Override
	public default Vec3i negate() { return set(0, 0, 0); }
	@Override
	public default Vec3i invert() { return set(-x(), -y(), -z()); }
	@Override
	public default Vec3i add(int value) { return add(value, value, value); }
	public default Vec3i add(Vec3i value) { return add(value.x(), value.y(), value.z()); }
	public default Vec3i add(int x, int y, int z) { return set(x() + x, y() + y, z() + z); }
	@Override
	public default Vec3i sub(int value) { return sub(value, value, value); }
	public default Vec3i sub(Vec3i value) { return sub(value.x(), value.y(), value.z()); }
	public default Vec3i sub(int x, int y, int z) { return set(x() - x, y() - y, z() - z); }
	@Override
	public default Vec3i multiply(int value) { return multiply(value, value, value); }
	public default Vec3i multiply(Vec3i value) { return multiply(value.x(), value.y(), value.z()); }
	public default Vec3i multiply(int x, int y, int z) { return set(x() * x, y() * y, z() * z); }
	@Override
	public default Vec3i devide(int value) { return devide(value, value, value); }
	public default Vec3i devide(Vec3i value) { return devide(value.x(), value.y(), value.z()); }
	public default Vec3i devide(int x, int y, int z) { return set(x() / x, y() / y, z() / z); }
	@Override
	public default Vec3i set(int value) { return set(value, value, value); }
	public default Vec3i set(Vec3i value) { return set(value.x(), value.y(), value.z()); }
	public Vec3i set(int x, int y, int z);
	public default double distanceTo(Vec3i value) { return distanceTo(value.x(), value.y(), value.z()); }
	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.x(), value.y(), value.z()); }
	public default long distanceToSquared(int x, int y, int z) {
		long xPos = x() - x;
		long yPos = y() - y;
		long zPos = z() - z;
		return (xPos * xPos) + (yPos * yPos) + (zPos * zPos);
	}
	
	@Override
	public default long lengthSquared() { return (x() * x()) + (y() * y()) + (z() * z()); }
	public default long dotProduct(Vec3i value) { return dotProduct(value.x(), value.y(), value.z()); }
	public default long dotProduct(int x, int y, int z) { return (x() * x) + (y() * y) + (z() * z); }
	public default Vec3i min(Vec3i other) { return min(other, this); }
	public default Vec3i min(Vec3i other, Vec3i result) { return min(other.x(), other.y(), other.z(), 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(x(), x), Math.min(y(), y), Math.min(z(), z)); }
	public default Vec3i max(Vec3i other) { return max(other, this); }
	public default Vec3i max(Vec3i other, Vec3i result) { return max(other.x(), other.y(), other.z(), 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(x(), x), Math.max(y(), y), Math.max(z(), z)); }
	public default Vec3i difference(Vec3i other) { return difference(other, this); }
	public default Vec3i difference(Vec3i other, Vec3i result) { return difference(other.x(), other.y(), other.z(), 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(x() - x, y() - y, z() - 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 ? x() : MathUtils.clamp(min, max, x()), (filter & Y) == 0 ? y() : MathUtils.clamp(min, max, y()), (filter & Z) == 0 ? z() : MathUtils.clamp(min, max, z())); }
	
	@Override
	public default Vec3i store(ByteBuffer buffer) {
		buffer.putInt(x()).putInt(y()).putInt(z());
		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(x()).put(y()).put(z());
		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.mutable((byte)x(), (byte)y(), (byte)z()) : Vec3b.of((byte)x(), (byte)y(), (byte)z()); }
	@Override
	public default Vec3s asShort() { return isMutable() ? Vec3s.mutable((short)x(), (short)y(), (short)z()) : Vec3s.of((short)x(), (short)y(), (short)z()); }
	@Override
	public default Vec3l asLong() { return isMutable() ? Vec3l.mutable(x(), y(), z()) : Vec3l.of(x(), y(), z()); }
	@Override
	public default Vec3f asFloat() { return isMutable() ? Vec3f.mutable(x(), y(), z()) : Vec3f.of(x(), y(), z()); }
	@Override
	public default Vec3d asDouble() { return isMutable() ? Vec3d.mutable(x(), y(), z()) : Vec3d.of(x(), y(), z()); }
	@Override
	public default Vec3i asMutable() { return isMutable() ? this : mutable(this); }
	@Override
	public default Vec3i asImmutable() { return isMutable() ? of(this) : this; }
	@Override
	public default Vec3i copyAsMutable() { return mutable(this); }
	@Override
	public default Vec3i copyAsImmutable() { return of(this); }
}
