var fs = require('fs');
module.exports = {
  '/api/log/start/:userID': {
    options: {
      userID: { required: true, description: 'ID of user', type: Number }
    },
    method: 'POST',
    summary: 'Get list of new cards',
    fn: async function(args) {
      fs.writeFile('./public/log/'+args.userID+'.jsons', JSON.stringify({
          type: 'START', date: +new Date(), data: args.body})+'\n', {'flag':'a'},
        function(err) {
          console.log(err);
        });

      return true;
    }
  },
  '/api/log/step/:userID': {
    options: {
      userID: { required: true, description: 'ID of user', type: Number }
    },
    method: 'POST',
    summary: 'Get list of new cards',
    fn: async function(args) {
      fs.writeFile('./public/log/'+args.userID+'.jsons', JSON.stringify({
        type: 'ANSWER', date: +new Date(), data: args.body})+'\n', {'flag':'a'},
        function(err) {
          console.log(err);
        });

      return true;
    }
  },
  '/api/log/any/:userID': {
    options: {
      userID: { required: true, description: 'ID of user', type: Number }
    },
    method: 'POST',
    summary: 'LOG BYPASS',
    fn: async function(args) {
      var d = new Date();
      fs.writeFile('./public/any/'+args.userID+'.jsons',
        ('0'+(d.getMonth()+1)).substr(-2)+
        ('0'+(d.getHours()+1)).substr(-2)+
        ('0'+(d.getMinutes()+1)).substr(-2)+
        ('0'+(d.getSeconds()+1)).substr(-2)+'\t'+
        JSON.stringify(args.body)+'\n',

        {'flag':'a'},
        function(err) {
          console.log(err);
        });

      return true;
    }
  }
};