-- @author DoomTero 2026
-- @copyright 2026 DoomTero - ZomboRut original work. ref:b71b6200
-- @license Proprietary. Not licensed for reuse, redistribution or derivative works without written permission from DoomTero. Ask - permission is obtainable. See ZomboRut/LICENSE.txt

local ZomboRutScene = require "ZomboRut/ZomboRutScene"

ZR_HeldDragController = ZR_HeldDragController or {}

local DEBUG = true
local function log(fmt, ...)
	if DEBUG then DebugLog.log(string.format("[ZR HeldDrag] " .. fmt, ...)) end
end

local SCENE_ID = "HeldDrag"

function ZR_HeldDragController.isActive(player)
	if not player then return false end
	if ZomboRutScene._active and ZomboRutScene._active[player] then
		return true
	end
	return player:getVariableString("ZR_SceneId") == SCENE_ID
end

function ZR_HeldDragController.start(player, zombie)
	if not player or not zombie then
		log("start abort: player=%s zombie=%s", tostring(player), tostring(zombie))
		return false
	end
	log("start: delegating to ZomboRutScene.playSceneFromAttacker (sceneId=%s)", SCENE_ID)
	return ZomboRutScene.playSceneFromAttacker(player, zombie, SCENE_ID)
end

function ZR_HeldDragController.stop(player)
	if not player then return end
	log("stop: ending scene")
	pcall(function() ZomboRutScene.endScene(player) end)
end

return ZR_HeldDragController
