'use strict';

// var config = require('../config');
// var twilio = require('twilio');
// var client = twilio(config.accountSid, config.authToken);
var fallbackCall = require('../lib/fallBackCall');

module.exports = function(app) {
  app.post('/StatusCallBack/:firstName/:lastName/:phoneNumber', function(req, res) {
    if ((req.body.AnsweredBy === 'machine') || (req.body.CallStatus === 'canceled' || req.body.CallStatus ===  'failed' || req.body.CallStatus ===  'no-answer')) {
      console.log('first call failed, time to try again.');
      res.type('text/xml');
      res.render('hangupMachine');
      fallbackCall.makeCall(req.params.firstName, req.params.lastName, req.params.phoneNumber);
    }
    console.log('call status is: ' + req.body.CallStatus);
  });
};

@@ -319,17 +319,16 @@
 %0A    if 
-(
 (req.bod
@@ -357,14 +357,12 @@
 ine'
-)
  %7C%7C 
-(
 req.
@@ -469,17 +469,16 @@
 answer')
-)
  %7B%0A     

call status wip