--[[
  Returns a dictionary with the model and difficulty data for each tile type and slope type
]]

local ServerStorage = game:GetService("ServerStorage")

local TileTypes = require(ServerStorage.Source.Constants.TileTypes)
local SlopeTypes = require(ServerStorage.Source.Constants.SlopeTypes)

return function()
	local tileIndex = {}

	local tiles = ServerStorage:FindFirstChild("Tiles")
	for _, tileType in pairs(TileTypes) do
		tileIndex[tileType] = {}

		local tileFolder = tiles:FindFirstChild(tileType)

		for _, slopeType in pairs(SlopeTypes) do
			tileIndex[tileType][slopeType] = {}

			local slopeFolder = tileFolder:FindFirstChild(slopeType)
			if slopeFolder then
				for _, model in pairs(slopeFolder:GetChildren()) do
					local difficultyObject = model:FindFirstChild("Difficulty")

					-- Clamp the difficulty value between 0 and 100 (as it is a percent)
					local difficulty = math.clamp(difficultyObject.Value, 0, 100)

					table.insert(
						tileIndex[tileType][slopeType],
						{
							model = model,
							difficulty = difficulty,
							type = tileType
						}
					)
				end
			end
		end
	end

	return tileIndex
end
