import { BimEngine } from '../bim-engine';
import { EngineEvents } from '../types/events';

export abstract class BimComponent {
    protected engine: BimEngine;

    constructor(engine: BimEngine) {
        this.engine = engine;
    }

    /**
     * Helper to send events easily
     */
    protected emit<K extends keyof EngineEvents>(event: K, payload: EngineEvents[K]): void {
        this.engine.emit(event, payload);
    }

    /**
     * Helper to listen to events easily
     * Returns an unsubscribe function
     */
    protected on<K extends keyof EngineEvents>(event: K, listener: (payload: EngineEvents[K]) => void): () => void {
        return this.engine.on(event, listener);
    }

    abstract destroy(): void;
}
