var App = null;
var Log = null
var Helper = null;
var Radio = null;


exports.init = function(express) {
  App = express;
  Log = App.get('Log');
  Helper = App.get('Helper');
  Radio = App.get('Radio');
};


exports.index = function(req, res, next) {
  //Log.debug('Router: transfer ' + Radio.countChannels() + ' channels to frontend');

  res.render('index', {
      title: 'Kitchen Radio',
      channels: Radio.getChannels()
    }
  );
}

exports.play = function(req, res, next) {
  var id = req.params.id;
  
  Log.trace('Router: ID ' + id + ' wanted');

  if(Helper.isDefinedAndNotNull(Radio.getChannel(id))) {
    Radio.play(id);
    res.sendStatus(200);
  } else {
    res.sendStatus(400);
  }
}