-- 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.PlayerEventDB = MereHealingFrames.PlayerEventDB or {}

-- this is a db of player event info, it's used to build the internal event structures and also for Matching things
-- up in the UI

-- Type is what kind of event:
--   number is a number
--   toggle is a boolean
--   calling is an indication of change in calling
--   ready is readycheck state (nil, true or false)

-- numbers may also have a MaxEvent field to indicate the linked Max Event, eg ManaChange and ManaMaxChange.
-- not all numbers will have a max, eg range

MereHealingFrames.PlayerEventDB.EventDB = {
    mana = {
        Type = 'number',
        MaxEvent = 'manaMax'
    },
    manaMax = {
        Type = 'number'
    },

    health = {
        Type = 'number',
        MaxEvent = 'healthMax'
    },
    healthMax = {
        Type = 'number'
    },

    absorb = {
        Type = 'number',
        MaxEvent = 'healthMax'
    },

    energy = {
        Type = 'number',
        MaxEvent = 'energyMax'
    },
    energyMax = {
        Type = 'number'
    },

    power = {
        Type = 'number',
        MaxValue = 100
    },

    role = {
        Type = 'number'
    },

    ready = {
        Type = 'ready'
    },

    aggro = {
        Type = 'toggle'
    },

    blocked = {
        Type = 'toggle'
    },

    offline = {
        Type = 'toggle'
    },

    dead = {
        Type = 'toggle'
    },

    afk = {
        Type = 'toggle'
    },

    name = {
        Type = 'text'
    },

    calling = {
        Type = 'calling'
    },

    range = {
        Type = 'number'
    },

    castRange = {
        Type = 'number'
    },

    inRange = {
        Type = 'toggle'
    }
}


function MereHealingFrames.PlayerEventDB.ValidateDB()
    for EventName, EventDetails in pairs(MereHealingFrames.PlayerEventDB.EventDB) do
        if (EventDetails.Type == nil) then
            print(string.format("Event %s has no defined Type", EventName))
        end

        if (EventDetails.Type == 'number') then
            if (EventDetails.MaxEvent ~= nil) then
                local maxEvent = MereHealingFrames.PlayerEventDB.EventDB[EventDetails.MaxEvent]
                if (maxEvent == nil) then
                    print(string.format("Event %s has a non-existent MaxEvent %s", EventName, EventDetails.MaxEvent))
                elseif (maxEvent.Type ~= 'number') then
                    print(string.format("Event %s uses a non-numeric MaxEvent %s", EventName, EventDetails.MaxEvent))
                end
            end
        elseif (EventDetails.Type == 'text') then
        elseif (EventDetails.Type == 'calling') then
        elseif (EventDetails.Type == 'toggle') then
        elseif (EventDetails.Type == 'ready') then
        else
            print(string.format("Event %s has unknown Type %s", EventName, EventDetails.Type))
        end
    end
end