local _
local powerGeneration = {
	[WN_GetSpellName(6572)] = 15, -- Revenge
	[WN_GetSpellName(23922)] = 20, -- Shield Slam
	[WN_GetSpellName(18499)] = 10, -- Berserker Rage
	[WN_GetSpellName(6673)] = 20, -- Battle Shout
	[WN_GetSpellName(469)] = 20, -- Commanding Shout
	[WN_GetSpellName(46953)] = 5, -- Sword and Board
	[WN_GetSpellName(33917)] = 5, -- Mangle
}

local rtnAmount
function WhatsNext_GetPowerGeneration(spellName)
	rtnAmount = powerGeneration[spellName] or 0
	
	if spellName == WN_GetSpellName(23922) and UnitBuffByID("player", 46953) then
		rtnAmount = rtnAmount + powerGeneration[WN_GetSpellName(46953)] 
	end
	
	return rtnAmount
end

local power, maxPower
WhatsNext:AddConditionalStatement("Minimum Power",{
	category = "Power",
	test = function(checkTable) 
		power = UnitPower(tostring(checkTable.unit))
		return power and power >= tonumber(checkTable.amount)
	end,
	text = function(checkTable) 
		return GetUnitDisplayText(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) 
		power = UnitPower(tostring(checkTable.unit))
		maxPower = UnitPowerMax(tostring(checkTable.unit))
		return power and maxPower and maxPower > 0 and tonumber(checkTable.amount) <= power / maxPower
	end,
	text = function(checkTable) 
		power = tonumber(checkTable.amount)
		return GetUnitDisplayText(checkTable.unit) .. "'s power is at or above " .. tostring(power and power*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(WN_GetSpellName(checkTable.spellName))
	end,
	text = function(checkTable) 
		return WN_GetSpellName(checkTable.spellName) .. " would generate excess rage."
	end,
	arguments = {
		spellName = {type = "spell", default = ""}
	}
})

WhatsNext:AddConditionalStatement("Maximum Power",{
	category = "Power",
	test = function(checkTable) 
		power = UnitPower(tostring(checkTable.unit))
		return power and power <= tonumber(checkTable.amount)
	end,
	text = function(checkTable) 
		return GetUnitDisplayText(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) 
		power = UnitPower(tostring(checkTable.unit))
		maxPower = UnitPowerMax(tostring(checkTable.unit))
		return power and maxPower and maxPower > 0 and tonumber(checkTable.amount) >= power / maxPower
	end,
	text = function(checkTable) 
		power = tonumber(checkTable.amount)
		return GetUnitDisplayText(checkTable.unit) .. "'s power is at or below " .. tostring(power and power*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) 
		power = UnitPower(tostring(checkTable.unit))
		maxPower = UnitPowerMax(tostring(checkTable.unit))
		return power and maxPower and maxPower - power >= tonumber(checkTable.amount)
	end,
	text = function(checkTable) 
		return GetUnitDisplayText(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) 
		power = UnitPower(tostring(checkTable.unit))
		maxPower = UnitPowerMax(tostring(checkTable.unit))
		return power and maxPower and maxPower - power <= tonumber(checkTable.amount)
	end,
	text = function(checkTable) 
		return GetUnitDisplayText(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) 
		return UnitPower("player") - WhatsNext_GetSpellCost(checkTable.spellName) >= tonumber(checkTable.amount)
	end,
	text = function(checkTable) 
		return "player's power would be at least " .. tostring(checkTable.amount) .. " after casting ".. WN_GetSpellName(checkTable.spellName) .."."
	end,
	arguments = {
		amount = {type = "integer", default = 0},
		spellName = {type = "spell", default = ""}
	}
})

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