package com.github.dannil.urldatabind;

import static spark.Spark.get;
import static spark.Spark.post;

import java.util.Collection;

import spark.Request;
import spark.Response;

import com.github.dannil.urldatabind.model.bind.Bind;

public class Router {

	private static Router router;

	public static Router getInstance() {
		if (router == null) {
			router = new Router();
		}
		return router;
	}

	private Router() {

	}

	public void createRoute(Collection<Bind<?>> binds) {
		for (Bind<?> b : binds) {
			switch (b.getRequestMethod()) {
				case GET:
					get(b.getPath(), b.getHttpType(), (request, response) -> createRoute(request, response, b));
					break;

				case POST:
					post(b.getPath(), b.getHttpType(), (request, response) -> createRoute(request, response, b));
					break;

				default:
					break;

			}
		}

		// for (Bind<?> b : this.bindController.getBinds()) {
		// get(b.getPath(), b.getHttpType(), (request, response) ->
		// createRoute(request, response, b));
		// }
		// get("/", (request, response) -> "Hello World!");
	}

	private Object createRoute(Request req, Response res, Bind<?> b) {
		res.type(b.getHttpType());
		return b.getHttpContent();
	}

}

@@ -100,39 +100,8 @@
 st;%0A
-%0Aimport java.util.Collection;%0A%0A
 impo
@@ -419,66 +419,24 @@
 ute(
-Collection%3C
 Bind%3C?%3E
-%3E
  bind
-s
 ) %7B%0A
-%09%09for (Bind%3C?%3E b : binds) %7B%0A%09
 %09%09sw
@@ -442,16 +442,19 @@
 witch (b
+ind
 .getRequ
@@ -467,25 +467,24 @@
 hod()) %7B%0A%09%09%09
-%09
 case GET:%0A%09%09
@@ -489,14 +489,16 @@
 %09%09%09%09
-%09
 get(b
+ind
 .get
@@ -498,32 +498,35 @@
 ind.getPath(), b
+ind
 .getHttpType(), 
@@ -572,37 +572,39 @@
 est, response, b
+ind
 ));%0A
-%09
 %09%09%09%09break;%0A%0A%09%09%09%09
@@ -602,17 +602,16 @@
 ak;%0A%0A%09%09%09
-%09
 case POS
@@ -621,15 +621,17 @@
 %09%09%09%09
-%09
 post(b
+ind
 .get
@@ -631,32 +631,35 @@
 ind.getPath(), b
+ind
 .getHttpType(), 
@@ -713,21 +713,23 @@
 ponse, b
+ind
 ));%0A
-%09
 %09%09%09%09brea
@@ -735,17 +735,16 @@
 ak;%0A%0A%09%09%09
-%09
 default:
@@ -744,17 +744,16 @@
 efault:%0A
-%09
 %09%09%09%09brea
@@ -762,235 +762,9 @@
 %0A%0A%09%09
-%09%7D%0A%09%09%7D%0A%0A%09%09// for (Bind%3C?%3E b : this.bindController.getBinds()) %7B%0A%09%09// get(b.getPath(), b.getHttpType(), (request, response) -%3E%0A%09%09// createRoute(request, response, b));%0A%09%09// %7D%0A%09%09// get(%22/%22, (request, response) -%3E %22Hello World!%22);
+%7D
 %0A%09%7D%0A

Tidy code!