import { EventHandler } from './EventHandler';
import { EventRegistry } from './EventRegistry';

class EventsManager {
    constructor() {
        this.eventRegistry = new EventRegistry();
    }

    subscribe(eventConfigs) {
        eventConfigs.forEach(config => {
            const { eventName, param, func, priority } = config;
            const eventHandler = new EventHandler({ eventName, param, func, priority });
            this.eventRegistry.addHandler(eventHandler);
        });
    }

    unsubscribe(eventName, func) {
        this.eventRegistry.removeHandler(eventName, func);
    }

    triggerEvent(eventName, eventArgs) {
        this.eventRegistry.trigger(eventName, eventArgs);
    }

    onEntityHitEntity(event) {
        this.triggerEvent('onEntityHitEntity', event);
    }

    onEntitySpawn(event) {
        this.triggerEvent('onEntitySpawn', event);
    }

    onEntityDie(event) {
        this.triggerEvent('onEntityDie', event);
    }

    onProjectileHitEntity(event) {
        this.triggerEvent('onProjectileHitEntity', event);
    }
    
    onitemStartUse(event) {
        this.triggerEvent('onitemStartUse', event);
    }
    
    onitemStopUse(event) {
        this.triggerEvent('onitemStopUse', event);
    }
    
    onitemReleaseUse(event) {
        this.triggerEvent('onitemReleaseUse', event);
    }

    onitemUse(event) {
        this.triggerEvent('onitemUse', event);
    }

    onprojectileHitBlock(event) {
        this.triggerEvent('onprojectileHitBlock', event);
    }

    onplayerPlaceBlock(event) {
        this.triggerEvent('onplayerPlaceBlock', event);
    }

    onplayerBreakBlockA(event) {
        this.triggerEvent('onplayerBreakBlockA', event);
    }
}

export { EventsManager };
