/**
 *    Copyright 2016 Sven Loesekann

   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 ch.xxx.trader.adapter.repository;

import java.util.Collection;

import org.bson.Document;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.mongodb.core.ReactiveMongoOperations;
import org.springframework.data.mongodb.core.index.Index;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import com.mongodb.client.result.DeleteResult;
import com.mongodb.reactivestreams.client.MongoCollection;

import ch.xxx.trader.usecase.services.MyMongoRepository;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@Service
public class ClientMongoRepository implements MyMongoRepository {
	private final ReactiveMongoOperations operations;

	public ClientMongoRepository(ReactiveMongoOperations operations) {
		this.operations = operations;
	}

	@Override
	public <T> Mono<T> save(T objectToSave) {
		return this.operations.save(objectToSave);
	}

	@Override
	public <T> Mono<T> findOne(Query query, Class<T> entityClass) {
		return this.operations.findOne(query, entityClass);
	}

	@Override
	public <T> Mono<T> findOne(Query query, Class<T> entityClass, String name) {
		return this.operations.findOne(query, entityClass, name);
	}

	@Override
	public <T> Flux<T> find(Query query, Class<T> entityClass) {
		return this.operations.find(query, entityClass);
	}

	@Override
	public <T> Flux<T> find(Query query, Class<T> entityClass, String collectionName) {
		return this.operations.find(query, entityClass, collectionName);
	}

	@Override
	public <T> Flux<T> insertAll(Mono<? extends Collection<? extends T>> batchToSave, String collectionName) {
		return this.operations.insertAll(batchToSave, collectionName);
	}

	@Override
	public Mono<String> ensureIndex(String collectionName, String propertyName) {
		Index myIndex = new Index(propertyName, Direction.DESC);
		myIndex.named(collectionName + "-" + propertyName);			
		return this.operations.indexOps(collectionName).ensureIndex(myIndex);
	}

	@Override
	public Mono<Boolean> collectionExists(String collectionName) {
		return this.operations.collectionExists(collectionName);
	}

	@Override
	public Mono<MongoCollection<Document>> createCollection(String collectionName) {
		return this.operations.createCollection(collectionName);
	}

	@Override
	public <T> Mono<T> insert(Mono<T> quote) {
		return this.operations.insert(quote);
	}

	@Override
	public <T> Mono<DeleteResult> remove(Mono<T> quote) {
		return this.operations.remove(quote);
	}
}

@@ -658,24 +658,56 @@
 ollection;%0A%0A
+import javax.validation.Valid;%0A%0A
 import org.b
@@ -720,16 +720,16 @@
 cument;%0A
-
 import o
@@ -1513,16 +1513,23 @@
 T%3E save(
+@Valid 
 T object
@@ -2210,16 +2210,23 @@
 sertAll(
+@Valid 
 Mono%3C? e
@@ -2943,32 +2943,32 @@
 %0A%09%7D%0A%0A%09@Override%0A
-
 %09public %3CT%3E Mono
@@ -2978,16 +2978,23 @@
  insert(
+@Valid 
 Mono%3CT%3E 

use validation