-- @author DoomTero 2026

local ZomboRutScene = require "ZomboRut/ZomboRutScene"

local BEING_FEMALE_ID   = "ZomboLustBeingFemale"
local INTERCOURSE_EVENT = "ZLBFIntercourse"

if not getActivatedMods():contains(BEING_FEMALE_ID) then
	return
end

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

log("detected '%s' — pregnancy integration enabled", BEING_FEMALE_ID)

ZomboRutScene.registerSceneStartCallback(function(player, active)
	if not player or not active then return end
	if not (active.cfg and active.cfg.pregnancyRisk) then return end
	local inv = player.getInventory and player:getInventory()
	if inv and inv:contains("ZLBF.Condom") then
		active.ctx = active.ctx or {}
		active.ctx.condomActive = true
		log("scene '%s' start: condom in play → zombie-sex sickness suppressed",
			tostring(active.sceneId))
	end
end)

ZomboRutScene.registerSceneEndCallback(function(player, active, result)
	if result ~= "Released" then return end
	if not player or not active then return end

	if not (active.cfg and active.cfg.pregnancyRisk) then return end

	if not (player.isFemale and player:isFemale()) then return end

	if not (Events and Events[INTERCOURSE_EVENT]) then
		log("scene '%s' completed but %s not registered — skipped",
			tostring(active.sceneId), INTERCOURSE_EVENT)
		return
	end

	log("scene '%s' completed → triggerEvent('%s')",
		tostring(active.sceneId), INTERCOURSE_EVENT)
	triggerEvent(INTERCOURSE_EVENT)
end)
