--core/unitframes.lua, the party/raid unit-frame engine facade (backend). this is the only unit-frame
--module the optimizer talks to: it turns the feature on or off. enabling (re)installs the secure code
--on the headers, starts the shared aura ticker, and registers the state drivers that show the frames
--in party / raid; disabling removes the drivers, hides the headers and stops the ticker. the secure
--skeleton itself is created at file-load in core/unitframes_secure.lua, and all secure work is deferred
--out of combat by the Secure submodule.

local _ = nil
local addonName, private = ...

private.Core = private.Core or {}
private.Core.UnitFrames = private.Core.UnitFrames or {}

local UnitFrames = private.Core.UnitFrames

--enables or disables the whole feature; called from the optimizer with the profile value. idempotent:
--StartTicker no-ops if already running and the secure changes are re-applied each time.
---@param enabled boolean
function UnitFrames:SetEnabled(enabled)
	if enabled then
		--(re)install the secure code so the latest sizes/keybinds apply, start rendering, then let the
		--state drivers show the headers in party / raid.
		self.Secure:UpdateAllHeaders()
		self.Auras:StartTicker()
		self.Secure:SetStateDriversEnabled(true)
	else
		--remove the drivers and hide the headers, then stop the ticker and drop all render state.
		self.Secure:SetStateDriversEnabled(false)
		self.Auras:StopTicker()
	end
end
