class EventRegistry {
    constructor() {
        this.eventHandlers = [];
    }

    addHandler(eventHandler) {
        this.eventHandlers.push(eventHandler);
        this.eventHandlers.sort((a, b) => b.priority - a.priority);
    }

    removeHandler(eventName, func) {
        this.eventHandlers = this.eventHandlers.filter(
            (h) => h.eventName !== eventName || h.func !== func
        );
    }

    trigger(eventName, eventArgs) {
        for (const eventHandler of this.eventHandlers) {
            if (eventHandler.eventName === eventName) {
                eventHandler.execute(eventArgs);
            }
        }
    }
}

export { EventRegistry };
