-- This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
-- To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/
-- or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

local MereHealingFrames, privateVars = ...

MereHealingFrames.BuffCache = {}
MereHealingFrames.BuffCache.Cache = {}

local BuffCache = MereHealingFrames.BuffCache

BuffCache.Enabled = true

function BuffCache.Enable()
	BuffCache.Enabled = true
end

function BuffCache.Disable()
	BuffCache.Enabled = false
end

function BuffCache.Save()
	return BuffCache.Cache
end

function BuffCache.Load(savedVars)
	BuffCache.Cache = savedVars
end

function BuffCache.UpdateCache(buffDetails)
	if not BuffCache.Enabled then return end

	local cacheEntry = BuffCache.Cache[buffDetails.name]

	if cacheEntry == nil then
		cacheEntry = {}
		cacheEntry.name = buffDetails.name
		cacheEntry.icon = buffDetails.icon
	end

	if buffDetails.debuff then
		cacheEntry.debuff = true
	else
		cacheEntry.buff = true
	end

	if buffDetails.poison then
		cacheEntry.poison = true
	end

	if buffDetails.disease then
		cacheEntry.poison = true
	end

	if buffDetails.curse then
		cacheEntry.curse = true
	end

	BuffCache.Cache[buffDetails.name] = cacheEntry
end