package triggers

import "sync"

// globalEngine holds a reference to the active trigger engine.
// Set by SetGlobalEngine at startup, used by handlers that need
// to wire triggers immediately on package install.
var (
	globalMu     sync.RWMutex
	globalEngine *Engine
)

// SetGlobalEngine stores the engine reference for use by handlers.
func SetGlobalEngine(e *Engine) {
	globalMu.Lock()
	globalEngine = e
	globalMu.Unlock()
}

// GlobalEngine returns the current engine, or nil.
func GlobalEngine() *Engine {
	globalMu.RLock()
	defer globalMu.RUnlock()
	return globalEngine
}
