--- Init.lua
-- Initialisation of the global addon structures
-- Load dependencies
-- Note: Ideally, this would be saved in the addon table
-- It'll remain global for the time being in order to maintain backwards compatibility
Spearity = LibStub("AceAddon-3.0"):NewAddon(
	"Spearity",
	"AceConsole-3.0",
	"AceEvent-3.0",
	"AceTimer-3.0",
	"LibSink-2.0",
	"AceBucket-3.0",
	"LibBars-1.0",
	"AceSerializer-3.0"
)
-- The TOC "Version" field is the single source of truth for the addon version.
local tocVersion = C_AddOns.GetAddOnMetadata("Spearity", "Version") or "0"

-- Human-readable version, used for display purposes
Spearity.VERSION = tocVersion

-- Numeric version, used for the export payload and db.profile.lastRevision.
-- Upstream Rarity used SVN-style rNNN revisions; semantic versions are encoded as major * 10000 + minor * 100 + patch,
-- which keeps the value monotonically increasing across the switch (1.0 -> 10000 sorts above the old r752).
local svnRevision = tocVersion:match("^r(%d+)")
if svnRevision then
	Spearity.MINOR_VERSION = tonumber(svnRevision)
else
	local major, minor, patch = tocVersion:match("^(%d+)%.?(%d*)%.?(%d*)")
	Spearity.MINOR_VERSION = (tonumber(major) or 0) * 10000 + (tonumber(minor) or 0) * 100 + (tonumber(patch) or 0)
end

-- Set up modules
Spearity.Statistics = {}
Spearity.Utils = {}

-- Global lookup tables (will be replaced eventually, but let's maintain backwards compatibility for now)
Spearity.items = {}
Spearity.architems = {}
Spearity.encounters = {}
Spearity.guids = {}
Spearity.npcs_to_items = {}
Spearity.zones = {}
Spearity.items_to_items = {}
Spearity.bagitems = {}
Spearity.tempbagitems = {}
Spearity.used = {}
