Dokumentaci tohoto modulu lze vytvořit na stránce Nápověda:Modul:Error

-- @brief
--  Error handling.
-- 
-- @author
--  [[meta:User:Danny B.]]
local Error = {}
----------------------------------------


Error.commonTypes = {
	missing = {
		message = "Chybí hodnota",
		category = "Doplnit hodnotu"
	},
	unknown = {
		message = "Neznámá hodnota",
		category = "Opravit hodnotu"
	},
	wrongType = {
		message = "Špatný formát",
		category = "Opravit formát"
	}
}


-- @brief
--  Generate the error message.
-- 
-- @param
--  errorData Table
-- 
-- @return
--  Wikitext
function Error.getMessage( errorData )
	
	local output
	local template = mw.text.trim( errorData.template or "" )
	local text = mw.text.trim( errorData.text or "" )
	
	
	for key, value in pairs( Error.commonTypes ) do
		if errorData[key] then
			text = Error.commonTypes[key].message .. " "
			if tonumber( errorData[key].paramName ) then
				text = text .. errorData[key].paramName .. ". parametru"
			else
				text = text .. "parametru „" .. errorData[key].paramName .. "“"
			end
			text = text .. " (" .. errorData[key].paramDesc .. ")."
		end
	end
	
	if template ~= "" then
		template = "<nowiki>{{</nowiki>[[Šablona:" .. template .. "|" .. template .. "]]<nowiki>}}</nowiki> — "
	end
	
	if text ~= "" then
		text = ": " .. template .. text
	elseif template ~= "" then
		text = ": " .. template .. "Chybné vložení."
	end
	
	output = "<strong class=\"error\">CHYBA" .. text .. "</strong>"
	
	return output
	
end


-- @brief
--  Generate the error category.
-- 
-- @param
--  errorData Table
-- 
-- @return
--  Wikitext
function Error.getCategory( errorData )
	
	local output
	local template = mw.text.trim( errorData.template or "" )
	local category = mw.text.trim( errorData.category or "" )
	
	
	for key, value in pairs( Error.commonTypes ) do
		if errorData[key] then
			category = Error.commonTypes[key].category .. " "
			if tonumber( errorData[key].paramName ) then
				category = category .. errorData[key].paramName .. ". parametru"
			else
				category = category .. "parametru „" .. errorData[key].paramName .. "“"
			end
		end
	end
	
	if category ~= "" then
		if template ~= "" then
			category = category .. " v šabloně " .. template
		end
	else
		category = mw.text.trim( "Opravit chybné volání šablony " .. template )
	end
	
	output = "[[Kategorie:Údržba:" .. category .. "]]"
	
	return output
	
end


-- @brief
--  Generate the error message and error category.
-- 
-- @param
--  errorData Table
-- 
-- @return
--  Wikitext
function Error.getText( errorData )
	
	local output = ""
	
	
	output = output .. Error.getMessage( errorData )
	output = output .. "<includeonly>" .. Error.getCategory( errorData ) .. "</includeonly>"
	
	return output
	
end


----------------------------------------
return Error