import express from 'express';
import debug from 'debug';

import authenticate from './routes/authenticate';
import playlist from './routes/playlists';
import waitlist from './routes/waitlist';
import booth from './routes/booth';
import users from './routes/users';
import chat from './routes/chat';

import Authentications from './models/authentication';
import Playlist from './models/playlist';
import History from './models/history';
import Media from './models/media';
import User from './models/user';

const log = debug('uwave:api:v1');

/**
 * creates a router for version 1 of the api
 *
 * @param {Object[]} middleware - all middleware that should be injected
 * @param {Object} wareOpts - middleware config, for more information see src/config/middleware.json.example
 * @param {Object} routerOpts - router config, for more information see {@link http://expressjs.com/4x/api.html#router}
 **/
export default function createV1(middleware, options = {}) {
  const router = express.Router(options);

  middleware.forEach((item, index) => {
    if (typeof item === 'function') {
      router.use(item);
      log(`registered middleware ${item.name}`);
    } else if (typeof item === 'object') {
      router.use(item.path, item.ware);
      log(`registered middleware ${item.middleware.name}`);
    } else {
      log(`problem with registering middleware at index: ${index}`);
    }
  });

  authenticate(router);
  playlist(router);
  waitlist(router);
  booth(router);
  users(router);
  chat(router);

  return router;
}

@@ -48,24 +48,34 @@
 m 'debug';%0A%0A
+// routes%0A
 import authe
@@ -304,16 +304,26 @@
 chat';%0A%0A
+// models%0A
 import A
@@ -335,17 +335,16 @@
 tication
-s
  from '.
@@ -368,16 +368,50 @@
 ation';%0A
+import User from './models/user';%0A
 import P
@@ -524,38 +524,75 @@
 a';%0A
-import User from './models/use
+%0A// middleware%0Aimport authenticator from './middleware/authenticato
 r';%0A
@@ -701,201 +701,16 @@
 ject
-%5B%5D%7D middleware - all middleware that should be injected%0A * @param %7BObject%7D wareOpts - middleware config, for more information see src/config/middleware.json.example%0A * @param %7BObject%7D routerOpt
+%7D option
 s - 
@@ -821,38 +821,33 @@
 ult 
-function createV1(middleware, 
+class V1 %7B%0A  constructor(
 opti
@@ -860,22 +860,23 @@
 %7B%7D) %7B%0A  
-const 
+  this.
 router =
@@ -908,430 +908,362 @@
 %0A%0A  
-middleware.forEach((item, index) =%3E %7B%0A    if (typeof item === 'function') %7B%0A      router.use(item
+  this.router.use(authenticator);%0A%0A    authenticate(this.router);%0A    playlist(this.router);%0A    waitlist(this.router
 );%0A    
-  log(%60registered middleware $%7Bitem.name%7D%60);%0A    %7D else if (typeof item === 'object') %7B%0A      router.use(item.path, item.ware)
+booth(this.router);%0A    users(this.router);%0A    chat(this.router);%0A  %7D%0A%0A  getRouter() %7B%0A    return this.router
 ;%0A  
-    log(%60registered middleware $%7Bitem.middleware.name%7D%60);%0A    %7D else %7B%0A      log(%60problem with registering middleware at index: $%7Bindex%7D%60);%0A    %7D%0A  %7D);%0A%0A  authenticate(router
+%7D%0A%0A  registerModels(server) %7B%0A    const mongoose = server.getMongoose();%0A    Authentication(mongoose
 );%0A  
-p
+  P
 laylist(
 rout
@@ -1262,103 +1262,85 @@
 ist(
-router);%0A  waitlist(router);%0A  booth(router);%0A  users(router);%0A  chat(router
+mongoose);%0A    History(mongoose);%0A    Media(mongoose);%0A    User(mongoose
 );%0A
-%0A
   
-return router;
+%7D
 %0A%7D%0A

refactor createAPI function into class