module.exports = (server, db) => {
  // import controllers
  const products = require('./controllers/products')(server, db)
  const groups = require('./controllers/groups')(server, db)
  const subgroups = require('./controllers/subgroups')(server, db)
  const orders = require('./controllers/orders')(server, db)
  const printer = require('./controllers/printer')(server, db)
  const additionals = require('./controllers/additionals')(server, db)

  // register routes
  server.get('/products', products.index)

  server.get('/groups', groups.index)
  server.get('/groups/:groupId', groups.show)
  server.get('/groups/:groupId/subgroups', groups.subgroups)

  server.get('/subgroups', subgroups.index)
  server.get('/subgroups/:subgroupId', subgroups.show)

  server.get('/orders', orders.index)
  server.get('/orders/:voucher/products', orders.products)
  server.post('/orders/finish', orders.store)
  server.post('/remove-product', orders.removeProduct)

  server.post('/print-order-pad', printer.index)

  server.get('/additionals', additionals.index)

  server.post('/check-password', (req, res, next) => {
    let success = (req.body.password === process.env.MASTER_PASSWORD)
    res.send({ success })
    next()
  })

  server.get('/test-connection', (req, res, next) => {
    res.send({ status: 'ok' })
    next()
  })

  server.get('/', (req, res, next) => {
    res.send('ibrsoft webservice')
    next()
  })
}
