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

import de.accso.flexinale.common.api.eventbus.EventBus;
import de.accso.flexinale.common.api.eventbus.EventContextHolder;
import de.accso.flexinale.common.api.eventbus.EventSubscriber;
import de.accso.flexinale.common.api.eventbus.EventSubscriptionAtStart;
import de.accso.flexinale.common.api.event.Event;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SuppressWarnings("unused")
public final class NopeEventBusSpy<E extends Event> implements EventBus<E> {
    private static final Logger LOGGER = LoggerFactory.getLogger(NopeEventBusSpy.class);

    private static final EventContextHolder eventContextHolder = new NopeContextHolder();

    private final Class<E> eventType; // might want to use this simplify the interface and get rid of the method's first parameter

    NopeEventBusSpy(final Class<E> eventType) {
        this.eventType = eventType;
    }

    @Override
    public void subscribe(final Class<E> eventType, final EventSubscriber<E> subscriber,
                          final EventSubscriptionAtStart eventSubscriptionAtStart) {
        LOGGER.debug("NopeEventBusSpy<%s>: subscriber %s registered but does nothing"
                .formatted(eventType.getSimpleName(), subscriber));
    }

    @Override
    public void subscribe(final EventSubscriber<Event> genericSubscriber,
                          final EventSubscriptionAtStart eventSubscriptionAtStart) {
        LOGGER.debug("NopeEventBusSpy<%s>: subscriber %s registered but does nothing"
                .formatted(eventType.getSimpleName(), genericSubscriber));
    }

    @Override
    public void unsubscribe(final Class<E> eventType, final EventSubscriber<E> subscriber) {
        LOGGER.debug("NopeEventBusSpy<%s>: subscriber %s unregistered but does nothing"
                .formatted(eventType.getSimpleName(), subscriber));
    }

    @Override
    public void unsubscribe(EventSubscriber<Event> genericSubscriber) {
        LOGGER.debug("NopeEventBusSpy<%s>: subscriber %s unregistered but does nothing"
                .formatted(eventType.getSimpleName(), genericSubscriber));
    }

    @Override
    public void unsubscribeAll() {
        LOGGER.debug("NopeEventBusSpy<%s>: all subscribers unregistered but does nothing"
                .formatted(eventType.getSimpleName()));
    }

    @Override
    public void publish(final Class<E> eventType, final E event) {
        LOGGER.info("NopeEventBusSpy<%s>: publish new event %s but does nothing".formatted(eventType, event));
    }

    @Override
    public EventContextHolder getEventContextHolder() {
        return eventContextHolder;
    }
}
