package com.gentics.mesh.demo.verticle;

import org.jacpfx.vertx.spring.SpringVerticle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.gentics.mesh.core.AbstractCustomVerticle;
import com.gentics.mesh.core.rest.node.NodeListResponse;
import com.gentics.mesh.core.rest.node.NodeResponse;
import com.gentics.mesh.core.rest.schema.SchemaListResponse;
import com.gentics.mesh.core.rest.schema.SchemaResponse;
import com.gentics.mesh.demo.DemoDataProvider;
import com.gentics.mesh.query.impl.PagingParameter;
import com.gentics.mesh.rest.MeshRestClient;

import io.vertx.core.Future;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;

/**
 * Dummy verticle that is used to setup basic demo data
 * 
 * @author johannes2
 *
 */
@Component
@Scope("singleton")
@SpringVerticle
public class CustomerVerticle extends AbstractCustomVerticle {

	private static Logger log = LoggerFactory.getLogger(CustomerVerticle.class);

	@Autowired
	private DemoDataProvider demoDataProvider;

	private MeshRestClient client;

	public CustomerVerticle() {
		super("test");
	}

	@Override
	public void registerEndPoints() throws Exception {
		demoDataProvider.setup();

//		vertx.eventBus().consumer("mesh-startup-complete", mh -> {
//
//			client = MeshRestClient.create("localhost", config().getInteger("port"), vertx);
//			client.setLogin("joe1", "test123");
//			client.login();
//
//			Future<SchemaListResponse> schemasFuture = client.findSchemas(new PagingParameter(1, 100));
//			schemasFuture.setHandler(rh -> {
//				if (rh.failed()) {
//					log.error("Could not load schemas", rh.cause());
//				} else {
//					SchemaListResponse list = rh.result();
//					for (SchemaResponse schema : list.getData()) {
//						log.info("Found schema {" + schema.getName() + "}");
//						client.getClientSchemaStorage().addSchema(schema);
//					}
//				}
//			});
//			route("/*").handler(rc -> {
//				log.info("Custom Verticle is handling a request");
//				Future<NodeListResponse> fut = client.findNodes("dummy", new PagingParameter(1, 100));
//
//				fut.setHandler(rh -> {
//					if (rh.failed()) {
//						rc.fail(rh.cause());
//					} else {
//						NodeListResponse resp = rh.result();
//						for (NodeResponse node : resp.getData()) {
//							log.info("Found nodes {" + node.getUuid() + "}");
//						}
//					}
//				});
//				rc.response().end("test");
//			});
//		});

	}
}

@@ -328,307 +328,27 @@
 esh.
-core.rest.node.NodeListResponse;%0Aimport com.gentics.mesh.core.rest.node.NodeResponse;%0Aimport com.gentics.mesh.core.rest.schema.SchemaListResponse;%0Aimport com.gentics.mesh.core.rest.schema.SchemaResponse;%0Aimport com.gentics.mesh.demo.DemoDataProvider;%0Aimport com.gentics.mesh.query.impl.PagingParamet
+demo.TestDataProvid
 er;%0A
@@ -397,37 +397,8 @@
 t;%0A%0A
-import io.vertx.core.Future;%0A
 impo
@@ -770,16 +770,18 @@
 owired%0A%09
+//
 private 
@@ -814,16 +814,60 @@
 rovider;
+%0A%09private TestDataProvider demoDataProvider;
 %0A%0A%09priva

Swap data provider