package de.accso.flexinale.common.infrastructure;

import de.accso.flexinale.common.api.eventbus.EventBusFactory;
import de.accso.flexinale.common.infrastructure.eventbus.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Configuration
public class FlexinaleCommonSpringFactory {

    // Eventbus via Kafka

    // default: used for scenarios using real distributed remote communication via Kafka
    // so when starting all three apps Besucherportal, Backoffice and Ticketing and also for "test-distributed"
    @Bean
    @Profile({"!test-integrated & !testdata & !configtest & !smoketest & !local"})
    public EventBusFactory createKafkaAsyncEventBusFactory(final KafkaAvailabilityChecker kafkaAvailabilityChecker) {
        return new KafkaAsyncEventBusFactory(kafkaAvailabilityChecker);
    }

    @Bean
    @Profile({"!test-integrated & !testdata & !configtest & !smoketest & !local"})
    public KafkaAvailabilityChecker createKafkaAvailabilityChecker() {
        return new KafkaAvailabilityChecker();
    }

    // --------------------------------------------------------------------------------------------------------------

    // Eventbus as in-memory with Spy

    // used in tests where publishers and subscribers need to communicate via an in-memory event bus
    // and where we need to look into the event chain via the spy
    @Bean
    @Profile({"test-integrated"})
    public EventBusFactory createInMemorySyncEventBusSpyFactory() {
        return new InMemorySyncEventBusSpyFactory();
    }

    // --------------------------------------------------------------------------------------------------------------

    // Eventbus as in-memory

    // used in scenarios where publishers and subscribers need to communicated via an in-memory event bus
    @Bean
    @Profile({"local"})
    public EventBusFactory createInMemorySyncEventBusFactory() {
        return new InMemorySyncEventBusFactory();
    }

    // --------------------------------------------------------------------------------------------------------------

    // Eventbus doing nothing

    // used in scenarios to clean and load test data where we do not want to send any event
    @Bean
    @Profile({"testdata | configtest | smoketest"})
    public EventBusFactory createNopeEventBusSpyFactory() {
        return new NopeEventBusSpyFactory();
    }
}
