local k=import("\046\046\047\097\115\115\105\103\110")local K=import("\046\046\047\116\121\112\101\075\101\121")local V=import("\046\046\047\102\117\110\099\116\105\111\110\115\047\116\121\112\101\111\102")local O={}setmetatable(O,{__tostring=function()return"\086\101\099\116\111\114\050"end})local x={}local T={}T[K]="\086\101\099\116\111\114\050"function T.__index(K,k)local V=(getmetatable(K)).internal if V[k]~=nil then return V[k]end if x[k]~=nil then return x[k]end error(string.format("\037\115 \105\115 \110\111\116 \097 \118\097\108\105\100 \109\101\109\098\101\114 \111\102 \086\101\099\116\111\114\050",tostring(k)),2)end function T.__add(K,k)return O.new(K.X+k.X,K.Y+k.Y)end function T.__sub(K,k)return O.new(K.X-k.X,K.Y-k.Y)end function T.__mul(K,k)if V(K)=="\086\101\099\116\111\114\050"and V(k)=="\086\101\099\116\111\114\050"then return O.new(K.X*k.X,K.Y*k.Y)elseif V(K)=="\086\101\099\116\111\114\050"and V(k)=="\110\117\109\098\101\114"then return O.new(K.X*k,K.Y*k)elseif V(K)=="\110\117\109\098\101\114"and V(k)=="\086\101\099\116\111\114\050"then return O.new(k.X*K,k.Y*K)else error("\097\116\116\101\109\112\116 \116\111 \109\117\108\116\105\112\108\121 \097 \086\101\099\116\111\114\050 \119\105\116\104 \097\110 \105\110\099\111\109\112\097\116\105\098\108\101 \118\097\108\117\101 \116\121\112\101 \111\114 \110\105\108")end end function T.__div(K,k)if V(K)=="\086\101\099\116\111\114\050"and V(k)=="\086\101\099\116\111\114\050"then return O.new(K.X/k.X,K.Y/k.Y)elseif V(K)=="\086\101\099\116\111\114\050"and V(k)=="\110\117\109\098\101\114"then return O.new(K.X/k,K.Y/k)elseif V(K)=="\110\117\109\098\101\114"and V(k)=="\086\101\099\116\111\114\050"then return O.new(k.X/K,k.Y/K)else error("\097\116\116\101\109\112\116 \116\111 \100\105\118\105\100\101 \097 \086\101\099\116\111\114\050 \119\105\116\104 \097\110 \105\110\099\111\109\112\097\116\105\098\108\101 \118\097\108\117\101 \116\121\112\101 \111\114 \110\105\108")end end function T.__eq(K,k)return K.X==k.X and K.Y==k.Y end function O.new(...)if select("\035",...)==0 then return O.new(0,0)end local K,V=...if type(K)~="\110\117\109\098\101\114"or type(V)~="\110\117\109\098\101\114"then error("\086\101\099\116\111\114\050\046\110\101\119 \116\097\107\101\115 \105\110 \050 \110\117\109\098\101\114\115",2)end local x={X=K,Y=V}local M=newproxy(true)k(getmetatable(M),T);(getmetatable(M)).internal=x return M end return O
local assign = import("../assign")
local typeKey = import("../typeKey")
local typeof = import("../functions/typeof")

local Vector2 = {}

setmetatable(Vector2, {
	__tostring = function()
		return "Vector2"
	end,
})

local prototype = {}

local metatable = {}
metatable[typeKey] = "Vector2"

function metatable:__index(key)
	local internal = getmetatable(self).internal

	if internal[key] ~= nil then
		return internal[key]
	end

	if prototype[key] ~= nil then
		return prototype[key]
	end

	error(string.format("%s is not a valid member of Vector2", tostring(key)), 2)
end

function metatable:__add(other)
	return Vector2.new(self.X + other.X, self.Y + other.Y)
end

function metatable:__sub(other)
	return Vector2.new(self.X - other.X, self.Y - other.Y)
end

function metatable:__mul(other)
	if typeof(self) == "Vector2" and typeof(other) == "Vector2" then
		return Vector2.new(self.X * other.X, self.Y * other.Y)
	elseif typeof(self) == "Vector2" and typeof(other) == "number" then
		return Vector2.new(self.X * other, self.Y * other)
	elseif typeof(self) == "number" and typeof(other) == "Vector2" then
		return Vector2.new(other.X * self, other.Y * self)
	else
		error("attempt to multiply a Vector2 with an incompatible value type or nil")
	end
end

function metatable:__div(other)
	if typeof(self) == "Vector2" and typeof(other) == "Vector2" then
		return Vector2.new(self.X / other.X, self.Y / other.Y)
	elseif typeof(self) == "Vector2" and typeof(other) == "number" then
		return Vector2.new(self.X / other, self.Y / other)
	elseif typeof(self) == "number" and typeof(other) == "Vector2" then
		return Vector2.new(other.X / self, other.Y / self)
	else
		error("attempt to divide a Vector2 with an incompatible value type or nil")
	end
end

function metatable:__eq(other)
	return self.X == other.X and self.Y == other.Y
end

function Vector2.new(...)
	if select("#", ...) == 0 then
		return Vector2.new(0, 0)
	end

	local X, Y = ...
	if type(X) ~= "number" or type(Y) ~= "number" then
		error("Vector2.new takes in 2 numbers", 2)
	end

	local internalInstance = {
		X = X,
		Y = Y,
	}

	local instance = newproxy(true)

	assign(getmetatable(instance), metatable)
	getmetatable(instance).internal = internalInstance

	return instance
end

return Vector2
