Module:PriceCalculator

Revision as of 08:56, 26 June 2025 by Ryan (talk | contribs)

Documentation for this module may be created at Module:PriceCalculator/doc

local p = {}

function p._calculate(price, priceType)
	price = tonumber(price)
	if not price or price < 0 then
		return "Invalid price"
	end

	local percent = {
		sell = 0.6675,
		minor = 0.5,
		major = 1.0
	}

	local factor = percent[priceType]
	if not factor then
		return "Invalid type"
	end

	return math.floor(price * factor + 0.5)
end

function p.calculate(frame)
	local args = frame:getParent().args
	local price = args.price or args[1]
	local priceType = args.type or args[2]
	return p._calculate(price, priceType)
end

-- This makes the module callable directly without a function name
return setmetatable(p, {
	__call = function(_, frame)
		return p.calculate(frame)
	end
})