'use strict';
var util = require('util'),
    path = require('path'),
    generators = require('yeoman-generator'),
    chalk = require('chalk'),
    _ = require('underscore.string'),
    scriptBase = require('../script-base');

var ServiceGenerator = module.exports = function ServiceGenerator(args, options, config) {
    generators.Base.apply(this, arguments);
    this.argument('name', { type: String, required: true });
    console.log('The service ' + this.name + ' is being created.');
    this.baseName = this.config.get('baseName');
    this.packageName = this.config.get('packageName');
    this.packageFolder = this.config.get('packageFolder');
    this.databaseType = this.config.get('databaseType');
};

util.inherits(ServiceGenerator, generators.Base);
util.inherits(ServiceGenerator, scriptBase);

ServiceGenerator.prototype.askFor = function askFor() {
    var cb = this.async();

    var prompts = [
    {
        type: 'confirm',
        name: 'useInterface',
        message: '(1/1) Do you want to use an interface for your service?',
        default: false
    }
    ]
    this.prompt(prompts, function (props) {
        this.useInterface = props.useInterface;
        cb();
    }.bind(this));
};

ServiceGenerator.prototype.files = function files() {

    this.serviceClass = _.capitalize(this.name);
    this.serviceInstance = this.name.toLowerCase();
    var insight = this.insight();
    insight.track('generator', 'service');
    insight.track('service/interface', this.useInterface);

    this.template('src/main/java/package/service/_Service.java',
    'src/main/java/' + this.packageFolder + '/service/' +  this.serviceClass + 'Service.java');

    if (this.useInterface) {
        this.template('src/main/java/package/service/impl/_ServiceImpl.java',
        'src/main/java/' + this.packageFolder + '/service/impl/' +  this.serviceClass + 'ServiceImpl.java');
    }
};

@@ -39,36 +39,8 @@
 '),%0A
-    path = require('path'),%0A
     
@@ -217,16 +217,91 @@
 rator = 
+generators.Base.extend(%7B%7D);%0A%0Autil.inherits(ServiceGenerator, scriptBase);%0A%0A
 module.e
@@ -308,25 +308,16 @@
 xports =
- function
  Service
@@ -329,34 +329,52 @@
 ator
-(args, options, config) %7B%0A
+.extend(%7B%0A    constructor: function() %7B%0A    
     
@@ -413,16 +413,20 @@
 ments);%0A
+    
     this
@@ -486,15 +486,83 @@
     
-console
+%7D,%0A%0A    initializing : %7B%0A        getConfig : function () %7B%0A            this
 .log
@@ -610,24 +610,32 @@
 created.');%0A
+        
     this.bas
@@ -663,32 +663,40 @@
 et('baseName');%0A
+        
     this.package
@@ -730,24 +730,32 @@
 kageName');%0A
+        
     this.pac
@@ -797,24 +797,32 @@
 geFolder');%0A
+        
     this.dat
@@ -870,143 +870,41 @@
 ');%0A
-%7D;%0A%0Autil.inherits(ServiceGenerator, generators.Base);%0Autil.inherits(ServiceGenerator, scriptBase);%0A%0AServiceGenerator.prototype.askFor =
+        %7D%0A    %7D,%0A%0A    prompting :
  fun
@@ -913,19 +913,17 @@
 ion 
-askFor
 () %7B%0A
+    
     
@@ -942,24 +942,28 @@
 s.async();%0A%0A
+    
     var prom
@@ -974,18 +974,26 @@
 = %5B%0A    
-%7B%0A
+    %7B%0A    
         
@@ -1017,16 +1017,20 @@
         
+    
 name: 'u
@@ -1043,16 +1043,20 @@
 rface',%0A
+    
         
@@ -1131,16 +1131,20 @@
         
+    
 default:
@@ -1150,16 +1150,20 @@
 : false%0A
+    
     %7D%0A  
@@ -1168,10 +1168,18 @@
     
+ 
-%5D%0A
+   %5D%0A    
     
@@ -1222,24 +1222,28 @@
 ) %7B%0A        
+  
+  
 this.useInte
@@ -1278,16 +1278,20 @@
         
+    
 cb();%0A  
@@ -1292,16 +1292,20 @@
 ();%0A    
+  
+  
 %7D.bind(t
@@ -1315,46 +1315,29 @@
 ));%0A
-%7D;%0A%0AServiceGenerator.prototype.files =
+    %7D,%0A%0A    writing :
  fun
@@ -1346,19 +1346,17 @@
 ion 
-files
 () %7B%0A
-%0A
+    
     
@@ -1400,24 +1400,28 @@
 .name);%0A    
+ 
+   
 this.service
@@ -1456,24 +1456,28 @@
 Case();%0A    
+ 
+   
 var insight 
@@ -1490,24 +1490,28 @@
 .insight();%0A
+    
     insight.
@@ -1541,24 +1541,28 @@
 vice');%0A    
+ 
+   
 insight.trac
@@ -1601,24 +1601,28 @@
 nterface);%0A%0A
+    
     this.tem
@@ -1674,24 +1674,28 @@
 .java',%0A    
+  
+  
 'src/main/ja
@@ -1771,24 +1771,28 @@
 ce.java');%0A%0A
+    
     if (this
@@ -1808,32 +1808,36 @@
 face) %7B%0A        
+  
+  
 this.template('s
@@ -1882,32 +1882,36 @@
 viceImpl.java',%0A
+    
         'src/mai
@@ -2007,13 +2007,25 @@
 ');%0A
+        %7D%0A
     %7D%0A
-%7D
+%0A%7D)
 ;%0A

restructure service generator