/*
 * Copyright 2014 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.usergrid.corepersistence;

import com.google.inject.AbstractModule;
import com.google.inject.assistedinject.FactoryModuleBuilder;
import org.apache.usergrid.persistence.collection.EntityCollectionManager;
import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
import org.apache.usergrid.persistence.collection.EntityCollectionManagerSync;
import org.apache.usergrid.persistence.collection.impl.EntityCollectionManagerImpl;
import org.apache.usergrid.persistence.collection.impl.EntityCollectionManagerSyncImpl;
import org.apache.usergrid.persistence.collection.mvcc.stage.write.UniqueValueSerializationStrategy;
import org.apache.usergrid.persistence.collection.mvcc.stage.write.UniqueValueSerializationStrategyImpl;
import org.apache.usergrid.persistence.collection.serialization.SerializationFig;
import org.apache.usergrid.persistence.collection.serialization.impl.SerializationModule;
import org.apache.usergrid.persistence.collection.service.impl.ServiceModule;
import org.apache.usergrid.persistence.graph.guice.GraphModule;
import org.apache.usergrid.persistence.index.EntityIndex;
import org.apache.usergrid.persistence.index.EntityIndexFactory;
import org.apache.usergrid.persistence.index.IndexFig;
import org.apache.usergrid.persistence.index.impl.EsEntityIndexImpl;
import org.safehaus.guicyfig.GuicyFigModule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * Guice Module that encapsulates Core Persistence.
 */
public class GuiceModule  extends AbstractModule {
    private static final Logger log = LoggerFactory.getLogger( GuiceModule.class );

    @Override
    protected void configure() {

        // Graph Module
        install( new GraphModule() );

        // Collection modules
        install( new GuicyFigModule( SerializationFig.class ) );
        install( new SerializationModule() );
        install( new ServiceModule() );
        install( new FactoryModuleBuilder()
            .implement( EntityCollectionManager.class, EntityCollectionManagerImpl.class )
            .implement( EntityCollectionManagerSync.class, EntityCollectionManagerSyncImpl.class )
            .build( EntityCollectionManagerFactory.class ) );
        bind( UniqueValueSerializationStrategy.class ).to( UniqueValueSerializationStrategyImpl.class );

        // QueryIndex modules
        install (new GuicyFigModule( IndexFig.class ));
        install( new FactoryModuleBuilder()
            .implement( EntityIndex.class, EsEntityIndexImpl.class )
            .build( EntityIndexFactory.class ) );

    }    
}

@@ -693,24 +693,128 @@
 ractModule;%0A
+import com.google.inject.Inject;%0Aimport com.google.inject.Provides;%0Aimport com.google.inject.Singleton;%0A
 import com.g
@@ -859,24 +859,24 @@
 uleBuilder;%0A
-
 import org.a
@@ -1099,16 +1099,90 @@
 erSync;%0A
+import org.apache.usergrid.persistence.collection.guice.MvccEntityDelete;%0A
 import o
@@ -1341,24 +1341,182 @@
 erSyncImpl;%0A
+import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntity;%0Aimport org.apache.usergrid.persistence.collection.mvcc.entity.impl.MvccEntityEvent;%0A
 import org.a
@@ -1951,32 +1951,466 @@
 .ServiceModule;%0A
+import org.apache.usergrid.persistence.core.consistency.AsyncProcessor;%0Aimport org.apache.usergrid.persistence.core.consistency.AsyncProcessorImpl;%0Aimport org.apache.usergrid.persistence.core.consistency.ConsistencyFig;%0Aimport org.apache.usergrid.persistence.core.consistency.LocalTimeoutQueue;%0Aimport org.apache.usergrid.persistence.core.consistency.TimeService;%0Aimport org.apache.usergrid.persistence.core.consistency.TimeoutQueue;%0A
 import org.apach
@@ -3956,12 +3956,575 @@
     %7D   
- 
+%0A%0A    @Provides%0A    @Singleton%0A    @Inject%0A    @MvccEntityDelete%0A    public AsyncProcessor%3CMvccEntityEvent%3CMvccEntity%3E%3E edgeDelete(%0A            @MvccEntityDelete final TimeoutQueue%3CMvccEntityEvent%3CMvccEntity%3E%3E queue, %0A            final ConsistencyFig consistencyFig) %7B%0A%0A        return new AsyncProcessorImpl%3C%3E(queue, consistencyFig);%0A    %7D%0A%0A    @Provides%0A    @Inject%0A    @Singleton%0A    @MvccEntityDelete%0A    public TimeoutQueue%3CMvccEntityEvent%3CMvccEntity%3E%3E edgeDeleteQueue(final TimeService timeService) %7B%0A        return new LocalTimeoutQueue%3C%3E(timeService);%0A    %7D
 %0A%7D%0A

Fix Guice injection errors.