package de.accso.flexinale.common.infrastructure.eventbus;

import de.accso.flexinale.common.api.eventbus.EventBus;
import de.accso.flexinale.common.api.event.Event;

public class InMemorySyncEventBusSpyFactory extends InMemorySyncEventBusFactory {
    @SuppressWarnings("unchecked")
    @Override
    public <E extends Event> EventBus<E> createOrGetEventBusFor(final Class<E> eventType) {
        EventBus<? extends Event> eventBus = eventTypeToEventBusMap.get(eventType);
        if (eventBus == null) {
            eventBus = new InMemorySyncEventBusSpy<>(eventType);
            eventTypeToEventBusMap.put(eventType, eventBus);
        }
        return (EventBus<E>) eventBus;
    }
}
