package io.github.binout.soccer.infrastructure.persistence.mongo;

import com.github.fakemongo.Fongo;
import com.mongodb.client.MongoDatabase;
import io.github.binout.soccer.infrastructure.persistence.TransactedScope;
import org.mongolink.MongoSession;
import org.mongolink.MongoSessionManager;
import org.mongolink.Settings;
import org.mongolink.domain.mapper.ContextBuilder;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;

/**
 * LECTRA
 *
 * @author b.prioux
 */
public class MongoConfiguration {

    @Produces
    @ApplicationScoped
    public MongoDatabase database() {
        Fongo fongo = new Fongo("Dev Server");
        return fongo.getDatabase("dev");
    }

    @Produces
    @ApplicationScoped
    public MongoSessionManager sessionManager(MongoDatabase database) {
        ContextBuilder contextBuilder = new ContextBuilder(getClass().getPackage().getName());
        return MongoSessionManager.create(contextBuilder, Settings.defaultInstance().withDatabase(database));
    }

    @Produces
    @TransactedScope
    public MongoSession session(MongoSessionManager sessionManager) {
        return sessionManager.createSession();
    }
}

@@ -95,16 +95,48 @@
 .Fongo;%0A
+import com.mongodb.MongoClient;%0A
 import c
@@ -643,24 +643,106 @@
 atabase() %7B%0A
+        String uri = System.getenv(%22MONGODB_URI%22);%0A        if (uri == null) %7B%0A    
         Fong
@@ -780,24 +780,28 @@
 %22);%0A        
+    
 return fongo
@@ -817,24 +817,153 @@
 ase(%22dev%22);%0A
+        %7D else %7B%0A            MongoClient client = new MongoClient(uri);%0A            return client.getDatabase(%22prod%22);%0A        %7D%0A
     %7D%0A%0A    @

introduce prod