import { EventEmitter } from 'events';

interface Events {
    'transaction-created': { id: number; data: string }; // Типизация событий
}

class TypedEventBus extends EventEmitter {
    emit<K extends keyof Events>(event: K, payload: Events[K]): boolean {
        return super.emit(event, payload);
    }

    on<K extends keyof Events>(event: K, listener: (payload: Events[K]) => void): this {
        return super.on(event, listener);
    }

    off<K extends keyof Events>(event: K, listener: (payload: Events[K]) => void): this {
        return super.off(event, listener);
    }
}

export const EventBus = new TypedEventBus();
