-- Recusively parses folders only and makes a table tree.
---@param rootFolder instance
---@param data table

function Database._Parse_R(dataRoot,rootFolder,data,_id)
	
	_id = _id and _id or 0
	local initialTable = {}
	
	-- Ignore the first folder which is our root
	if _id > 0 then
		initialTable = { ["id"] = _id + 1 }
		dataRoot[rootFolder.name] = initialTable -- Store by Name
	end

    -- Store attributes
    local attributes = rootFolder:GetAttributes()
    for name, value in pairs(attributes) do
		initialTable[name] = value
	end

    -- Recursively parse every child that is a folder
    for _, child in ipairs(rootFolder:GetChildren()) do
        -- Recursively parse the folders only
		if child.ClassName == "Folder" then
			_id = _id + 1
			Database._Parse_R(dataRoot,child,initialTable,_id)
        else
            -- If it's not a folder then store it as a reference
			initialTable[child.name] = child
        end
	end
	

end

return Database
