---@class AddonPrivate
local Private = select(2, ...)

---@class Events
local events = {}
Private.Events = events

function events:InitEvents()
    local addon = Private.Addon
    addon:RegisterEvent("PLAYER_ENTERING_WORLD", function ()
        self:UpdateData()
    end)
    addon:RegisterEvent("ACHIEVEMENT_EARNED", function ()
        self:UpdateData()
    end)
    addon:RegisterEvent("CRITERIA_UPDATE", function ()
        self:UpdateData()
    end)
    -- Refresh the objective HUDs when the player changes zone/subzone.
    addon:RegisterEvent("ZONE_CHANGED_NEW_AREA", function ()
        self:RefreshHuds()
    end)
    addon:RegisterEvent("ZONE_CHANGED", function ()
        self:RefreshHuds()
    end)
end

function events:RefreshHuds()
    if Private.NearbyHud then Private.NearbyHud:Refresh() end
    if Private.RouteHud then Private.RouteHud:Refresh() end
end

function events:UpdateData()
    Private.UI:QueueUpdate()
    if Private.Objectives then
        Private.Objectives:InvalidateSummaries()
        Private.Objectives:InvalidateInstances()
    end
    self:RefreshHuds()
end