'use strict';

var path = require('path');
var appRoot = path.join(__dirname, '../../..');
var fs = require('fs');
var hbs = require('hbs');

var utils = require(path.join(appRoot, './lib/utils'));
var resource = require('./resource');

const invocationKey = 'node_0_12';

function generate (service) {
  // console.log(service);
  var resources = service.resources;
  var clients = [];

  resources.forEach(function (rSource) {
    clients.push(resource.createResource(rSource, service.imports));
  });

  var hbsFilePath = path.join(appRoot, 'public/templates', invocationKey, 'client.hbs');
  var hbsFileContents = fs.readFileSync(hbsFilePath).toString('utf-8');
  var template = hbs.handlebars.compile(hbsFileContents);

  var model = {
    constructorName: utils.alphaNumOnly(utils.capitalizeFirstLetter(service.name)),
    clients: clients
  };

  return [{
    name: service.name + '.js',
    dir: 'app/api/' + service.name,
    contents: template(model)
  }];
}

module.exports = {
  generate: generate
};

@@ -300,35 +300,8 @@
 ) %7B%0A
-  // console.log(service);%0A
   va
@@ -831,11 +831,58 @@
 urn 
+new Promise(function (resolve) %7B%0A    resolve(
 %5B%7B%0A
+  
     
@@ -913,16 +913,18 @@
 s',%0A    
+  
 dir: 'ap
@@ -947,16 +947,18 @@
 e.name,%0A
+  
     cont
@@ -985,11 +985,22 @@
 )%0A  
-%7D%5D;
+  %7D%5D);%0A  %7D);%0A%0A
 %0A%7D%0A%0A

Update node_0_12 client to use Promises