'use strict'

const _ = require('lodash')
const lib = require('.')

module.exports = {

  /**
   * Compile controller handlers into route objects
   */
  getControllerFootprints (app) {
    const controllers = _.omit(app.controllers, _.get(app.config, 'footprints.controllers.ignore'))
    const prefix = _.get(app.config, 'footprints.prefix')

    return _.flatten(_.map(controllers, (controller, controllerName) => {

      return _.map(controller.methods, handlerName => {
        return {
          method: _.get(app.config, 'footprints.controllers.method') || [ 'GET', 'POST' ],
          path: lib.Util.getHandlerPath(app, prefix, controller.id, handlerName),
          handler: lib.Util.getControllerHandler(controllerName, handlerName)
        }
      })
    }))
  },

  /**
   * Select the model footprint routes that the configuration allows.
   */
  getModelFootprints (app) {
    const actionsConfig = _.get(app.config, 'footprints.models.actions')

    return _.filter(lib.Routes, route => {
      const handlerName = lib.Util.getHandlerName(route.handler)
      return actionsConfig[handlerName]
    })
  },

  getControllerHandler (controllerName, handlerName) {
    return `${controllerName}.${handlerName}`
  },

  getHandlerName (routeHandler) {
    return (routeHandler || '').split('.')[1]
  },

  getHandlerPath (app, prefix, controllerId, handlerName) {
    return app.packs.router.util.getRoutePath([
      '/', prefix, controllerId, handlerName
    ])
  }
}

@@ -958,41 +958,107 @@
 s')%0A
-%0A
     
-return _.filter(lib.Routes, 
+const prefix = _.get(app.config, 'footprints.prefix');%0A%0A    return _(lib.Routes)%0A      .filter(
 rout
@@ -1060,24 +1060,26 @@
 (route =%3E %7B%0A
+  
       const 
@@ -1133,24 +1133,26 @@
 dler)%0A      
+  
 return actio
@@ -1173,25 +1173,120 @@
 erName%5D%0A    
-%7D
+  %7D)%0A      .map(route =%3E Object.assign(route, %7B path: %60$%7Bprefix%7D$%7Broute.path%7D%60 %7D))%0A      .value(
 )%0A  %7D,%0A%0A  ge

Fix #5