local GC = select(2, ...)

--[[
--LootManager
lootmanager = {}
	lootmanager["ZoneLoc"] = ""			-- will hold location of sessions
	lootmanager["LootSession"] = ""		-- will hold the sessions
	lootmanager["LootedItems"] = ""		-- will hold what was looted
--GC.LootManager = lootmanager
--]]

-- Location, toon, session date/time, items looted, value
-- searchable by item or location 

function LogLoot(itemID, itemLink, itemValue)
    -- add in to store the data by key/each toon

    GC.Debug.Log("LootManager called")
    GC.Debug.Log("LM itemID: " .. itemID)
    GC.Debug.Log("LM itemLink: " .. itemLink)
    GC.Debug.Log("LM itemValue: " .. itemValue)
    -- get count of index
    local indexCounter = table.getn(LOOTMANAGER)
    GC.Debug.Log("table rows: " .. indexCounter)
    -- add next looted item to next index number
    local i = indexCounter + 1
    table.insert(LOOTMANAGER, i, itemLink)
    -- table.foreach(LOOTMANAGER, print)

    GC.Debug.Log("Log to db: " .. itemLink)
    -- add session details
    local hour, minute = GetGameTime()
    GallywixCoinsDB.global.session = (hour .. ":" .. minute)

    -- add zone details 
    local zoneInfo
    local currentMapID = C_Map.GetBestMapForUnit("player")
    if currentMapID then
        GC.Debug.Log("currentMapID: " .. currentMapID)
        zoneInfo = C_Map.GetMapInfo(currentMapID)
        GC.Debug.Log("zoneInfo: " .. zoneInfo.name)
        zoneInfo = zoneInfo and zoneInfo.name
    else
        zoneInfo = {name = "Unknown"}
        GC.Debug.Log("Unknown location!")
    end

    -- add looted items from session and location
    GallywixCoinsDB.global.location = zoneInfo
    local newLoot = (itemID .. "," .. itemValue .. "," .. itemLink)
    local curLoot = GallywixCoinsDB.global.loot or ""
    GallywixCoinsDB.global.loot = (newLoot .. "\n" .. curLoot)
end

