/*
 * Copyright (c) 2018, 2026, Oracle and/or its affiliates.
 * Licensed under The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 */
const EVENT_ISSUE="on-jaf-issue";const EVENT_MESSAGE="on-jaf-message";const EVENT_SUMMARY="on-jaf-summary";const EVENTS=[EVENT_ISSUE,EVENT_MESSAGE,EVENT_SUMMARY];function JafEvents(){this._emitter=null;this._listeners=[];this.JAF_EVENT_ISSUE=EVENT_ISSUE;this.JAF_EVENT_MESSAGE=EVENT_MESSAGE;this.JAF_EVENT_SUMMARY=EVENT_SUMMARY};JafEvents.prototype.setListener=function(evName,fn,obj){if(EVENTS.includes(evName)){if(!this._emitter){var EventEmitter=require("events").EventEmitter;this._emitter=new EventEmitter}this._listeners.push({event:evName,fn:fn,obj:obj});this._emitter.on(evName,fn)}};JafEvents.prototype.emit=function(evName,obj){if(this._emitter)this._emitter.emit(evName,obj,this._getEventExtra(evName))};JafEvents.prototype.removeAllListeners=function(evName){if(this._emitter){if(evName){this._emitter.removeAllListeners(evName);this._removeFromInternalList(evName)}else{this._emitter.removeAllListeners();this._listeners.length=0}}};JafEvents.prototype.removeListener=function(evName,fn){var a,i;if(!this._emitter){return}a=this._emitter.listeners(evName);for(i=0;i<a.length;i++){if(a[i]===fn){this._emitter.removeListener(evName,fn)}}this._removeFromInternalList(evName,fn)};JafEvents.prototype._removeFromInternalList=function(evName,fn){if(this._listeners){let listener,i;for(i=0;i<this._listeners.length;i++){listener=this._listeners[i];if(evName===listener.event){if(fn&&fn!==listener.fn){continue}this._listeners.splice(i,1);i--}}}};JafEvents.prototype._getEventExtra=function(evName){var listener,i,ret;for(i=0;i<this._listeners.length;i++){listener=this._listeners[i];if(evName===listener.event){ret=listener.obj;break}}return ret};module.exports=JafEvents;