package de.cpg.shared.event_sourcing.configuration;

import akka.actor.ActorSystem;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.uuid.Generators;
import com.fasterxml.uuid.StringArgGenerator;
import de.cpg.shared.event_sourcing.service.CommandBus;
import de.cpg.shared.event_sourcing.service.CommandBusImpl;
import de.cpg.shared.event_sourcing.service.EventBus;
import de.cpg.shared.event_sourcing.service.EventBusImpl;
import eventstore.Settings;
import eventstore.UserCredentials;
import eventstore.j.EsConnection;
import eventstore.j.EsConnectionFactory;
import eventstore.j.SettingsBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.net.InetSocketAddress;

@Configuration
public class EventStore {

    @Value("${eventstore.username:admin}")
    private String username;

    @Value("${eventstore.password:changeit}")
    private String password;

    @Value("${eventstore.hostname:localhost}")
    private String hostname;

    @Value("${eventstore.port:1113}")
    private int port;

    @Bean
    public ActorSystem actorSystem() {
        return ActorSystem.create();
    }

    @Bean
    public Settings settings() {
        return new SettingsBuilder()
                .address(new InetSocketAddress(hostname, port))
                .defaultCredentials(new UserCredentials(username, password))
                .build();
    }

    @Bean
    public EsConnection esConnection(final ActorSystem system, final Settings settings) {
        return EsConnectionFactory.create(system, settings);

    }

    @Bean
    public StringArgGenerator uuidGenerator() {
        return Generators.nameBasedGenerator();
    }

    @Bean
    public ObjectMapper objectMapper() {
        return new ObjectMapper();
    }

    @Bean
    public CommandBus commandBus(final ObjectMapper objectMapper, final StringArgGenerator uuidGenerator, final EsConnection esConnection) {
        return new CommandBusImpl(objectMapper, uuidGenerator, esConnection);
    }

    @Bean
    public EventBus eventBus(final EsConnection esConnection, final ActorSystem actorSystem) {
        return new EventBusImpl(esConnection, actorSystem);
    }
}

@@ -171,54 +171,8 @@
 rs;%0A
-import com.fasterxml.uuid.StringArgGenerator;%0A
 impo
@@ -1133,32 +1133,33 @@
 lic ActorSystem 
+_
 actorSystem() %7B%0A
@@ -1227,44 +1227,96 @@
 lic 
-Settings settings() %7B%0A        return
+EsConnection _esConnection(final ActorSystem system) %7B%0A        final Settings settings =
  new
@@ -1505,506 +1505,120 @@
 ();%0A
-    %7D%0A%0A    @Bean%0A    public EsConnection esConnection(final ActorSystem system, final Settings settings) %7B%0A        return EsConnectionFactory.create(system, settings);%0A%0A    %7D%0A%0A    @Bean%0A    public StringArgGenerator uuidGenerator() %7B%0A        return Generators.nameBasedGenerator();%0A    %7D%0A%0A    @Bean%0A    public ObjectMapper objectMapper() %7B%0A        return new ObjectMapper();%0A    %7D%0A%0A    @Bean%0A    public CommandBus commandBus(final ObjectMapper objectMapper, final StringArgGenerator uuidGenerator, 
+%0A        return EsConnectionFactory.create(system, settings);%0A    %7D%0A%0A    @Bean%0A    public CommandBus commandBus(
 fina
@@ -1682,17 +1682,21 @@
 BusImpl(
-o
+new O
 bjectMap
@@ -1702,13 +1702,31 @@
 pper
-, uui
+(), Generators.nameBase
 dGen
@@ -1731,16 +1731,18 @@
 enerator
+()
 , esConn

Simplify bean configuration