local powerGeneration = {
	["Revenge"] = 15,
	["Shield Slam"] = 20,
	["Berserker Rage"] = 10,
	["Battle Shout"] = 20,
	["Commanding Shout"] = 20,
	["Sword and Board"] = 5,
	["Mangle"] = 5,
}

function WhatsNext_GetPowerGeneration(spellName)
	local rtnAmount = powerGeneration[spellName] or 0
	
	if spellName == "Shield Slam" and UnitBuff("player", "Sword and Board") then
		rtnAmount = rtnAmount + powerGeneration["Sword and Board"] 
	end
	
	return rtnAmount
end

WhatsNext:AddConditionalStatement("Minimum Power",{
	category = "Power",
	test = function(checkTable) 
		local power = UnitPower(tostring(checkTable.unit))
		return power and power >= tonumber(checkTable.amount)
	end,
	text = function(checkTable) 
		return tostring(checkTable.unit) .. "'s power is at or above " .. tostring(checkTable.amount) .. "."
	end,
	arguments = {
		unit = {type = "dropdown", default = "player", possibleValues = WhatsNext.valueLists.unitAny},
		amount = {type = "integer", default = 0}
	}
})

WhatsNext:AddConditionalStatement("Minimum Power Percent",{
	category = "Power",
	test = function(checkTable) 
		local power = UnitPower(tostring(checkTable.unit))
		local maxPower = UnitPowerMax(tostring(checkTable.unit))
		return power and maxPower and maxPower > 0 and tonumber(checkTable.amount) <= power / maxPower
	end,
	text = function(checkTable) 
		local amountNum = tonumber(checkTable.amount)
		return tostring(checkTable.unit) .. "'s power is at or above " .. tostring(amountNum and amountNum*100 or checkTable.amount) .. "%."
	end,
	arguments = {
		unit = {type = "dropdown", default = "player", possibleValues = WhatsNext.valueLists.unitAny},
		amount = {type = "percent", default = .5}
	}
})

WhatsNext:AddConditionalStatement("Excess Power",{
	category = "Power",
	test = function(checkTable) 
		return UnitPowerMax("player") < UnitPower("player") + WhatsNext_GetPowerGeneration(checkTable.spellName)
	end,
	text = function(checkTable) 
		return tostring(checkTable.spellName) .. " would generate excess rage."
	end,
	arguments = {
		spellName = {type = "text", default = ""}
	}
})

WhatsNext:AddConditionalStatement("Maximum Power",{
	category = "Power",
	test = function(checkTable) 
		local power = UnitPower(tostring(checkTable.unit))
		return power and power <= tonumber(checkTable.amount)
	end,
	text = function(checkTable) 
		return tostring(checkTable.unit) .. "'s power is at or below " .. tostring(checkTable.amount) .. "."
	end,
	arguments = {
		unit = {type = "dropdown", default = "player", possibleValues = WhatsNext.valueLists.unitAny},
		amount = {type = "integer", default = 0}
	}
})

WhatsNext:AddConditionalStatement("Maximum Power Percent",{
	category = "Power",
	test = function(checkTable) 
		local power = UnitPower(tostring(checkTable.unit))
		local maxPower = UnitPowerMax(tostring(checkTable.unit))
		return power and maxPower and maxPower > 0 and tonumber(checkTable.amount) >= power / maxPower
	end,
	text = function(checkTable) 
		local amountNum = tonumber(checkTable.amount)
		return tostring(checkTable.unit) .. "'s power is at or below " .. tostring(amountNum and amountNum*100 or checkTable.amount) .. "%."
	end,
	arguments = {
		unit = {type = "dropdown", default = "player", possibleValues = WhatsNext.valueLists.unitAny},
		amount = {type = "percent", default = .5}
	}
})

WhatsNext:AddConditionalStatement("Minimum Missing Power",{
	category = "Power",
	test = function(checkTable) 
		local power = UnitPower(tostring(checkTable.unit))
		local maxPower = UnitPowerMax(tostring(checkTable.unit))
		return power and maxPower and maxPower - power >= tonumber(checkTable.amount)
	end,
	text = function(checkTable) 
		return tostring(checkTable.unit) .. "'s power is at least " .. tostring(checkTable.amount) .. " below their maximum power."
	end,
	arguments = {
		unit = {type = "dropdown", default = "player", possibleValues = WhatsNext.valueLists.unitAny},
		amount = {type = "integer", default = 0}
	}
})

WhatsNext:AddConditionalStatement("Maximum Missing Power",{
	category = "Power",
	test = function(checkTable) 
		local power = UnitPower(tostring(checkTable.unit))
		local maxPower = UnitPowerMax(tostring(checkTable.unit))
		return power and maxPower and maxPower - power <= tonumber(checkTable.amount)
	end,
	text = function(checkTable) 
		return tostring(checkTable.unit) .. "'s power is no more than " .. tostring(checkTable.amount) .. " below their maximum power."
	end,
	arguments = {
		unit = {type = "dropdown", default = "player", possibleValues = WhatsNext.valueLists.unitAny},
		amount = {type = "integer", default = 0}
	}
})

WhatsNext:AddConditionalStatement("Minimum Resultant Power",{
	category = "Power",
	test = function(checkTable) 
		local _, _, _, cost, _, _, _, _, _ = GetSpellInfo(checkTable.spellName)
		return UnitPower("player") - cost >= tonumber(checkTable.amount)
	end,
	text = function(checkTable) 
		return "player's power would be at least " .. tostring(checkTable.amount) .. " after casting ".. tostring(checkTable.spellName) .."."
	end,
	arguments = {
		amount = {type = "integer", default = 0},
		spellName = {type = "text", default = ""}
	}
})

WhatsNext:AddConditionalStatement("Maximum Resultant Power",{
	category = "Power",
	test = function(checkTable) 
		local _, _, _, cost, _, _, _, _, _ = GetSpellInfo(checkTable.spellName)
		return UnitPowerMax("player") - cost <= tonumber(checkTable.amount)
	end,
	text = function(checkTable) 
		return "player's power would be no more than " .. tostring(checkTable.amount) .. " after casting ".. tostring(checkTable.spellName) .."."
	end,
	arguments = {
		amount = {type = "integer", default = 0},
		spellName = {type = "text", default = ""}
	}
})