--I am an academic weapon and machine.

local MWorks = require(game:GetService("ReplicatedStorage"):WaitForChild("Package").MWorks)
local module = {}

function module:setupUpdate() --Not used externally. Used for setting up classes of all types
	self.Updated = MWorks.newBindable()
end

function module.newClass(attributes)
	local self = {}
	if attributes then 
		for i,v in pairs(attributes) do
			self[i] = v
		end
	end
	setmetatable(self,{
		__index = module;
	})
	self:setupUpdate()
	return self
end

function module:newSubClass(Name,attributes)
	local subClass = {}
	self[Name] = subClass
	if attributes then 
		for i,v in pairs(attributes) do
			self[i] = v
		end
	end
	setmetatable(subClass,{__index = self})
	subClass:setupUpdate()
	return subClass
end

function module:Update(...)
	local args = table.pack(...)
	if type(args[1]) == "table" then 
		local Table = args[1]
		for i,v in pairs(Table) do
			if self[i] then 
				self[i] = v
				self.Updated:Fire(i,v)
			end
		end
	elseif args[1] ~= nil then  
		local Name = args[1]
		local Value = args[2]
		self[Name] = Value
		self.Updated:Fire(Name,Value)
	else 
		self.Updated:Fire()
	end
end

function module:newValue(...)
	local args = table.pack(...)
	local index; 
	local Value;
	if #args < 1 then return end 
	if #args > 1 then 
		index = args[1]
		Value = args[2]
	else 
		index = #self+1
		Value = args[1]
	end
	self[index] = Value 
	self:Update(index,Value)
	return index 
end

function module:removeValue(index)
	if self[index] == nil then return end 
	self[index] = nil 
	self:Update()
end

return module
