local settings = require("core.settings")

--- Include one selected settings layer and report real failures while allowing absent optional files
-- @param filename string|nil lowercase settings filename
-- @param description string readable layer name used in errors
-- @param filename_error string|nil earlier filename lookup error
local function include_settings(filename, description, filename_error)
	if not filename then
		error(string.format("Could not locate %s: %s", description, tostring(filename_error)))
	end

	local included, include_error = settings.include(filename)
	if included == nil then
		error(string.format("Could not include %s: %s", description, tostring(include_error)))
	end
end

-- Load Alpha starting settings first when the build supplies them
include_settings("alpha.lua", "alpha settings")

-- Later layers intentionally override earlier values with increasingly specific settings
include_settings("global.lua", "global settings")

local computer_filename, computer_error = settings.computer_filename()
include_settings(computer_filename, "computer settings", computer_error)

local user_computer_filename, user_computer_error = settings.user_computer_filename()
include_settings(user_computer_filename, "user and computer settings", user_computer_error)
