var generators = require('yeoman-generator');
var util = require('../util');

var filter = {};

module.exports = generators.Base.extend({
  // The name `constructor` is important here
  constructor: function () {
    // Calling the super constructor is important so our generator is correctly set up
    generators.Base.apply(this, arguments);
    
     var self = this;
    
    self.argument('name', { type: String, required: false });
    self.option('path');
    
    filter.name = self.name;
    filter.path = util.normalizePath(self.options.path);
    
    var parentAssets = self.config.get("assetsFolder");
    
    var appAssets = (parentAssets == "public/") ? "public/app/" : "app/";
    
    filter.assets = appAssets + "filters/";
    
  },
  
  prompting: function () {
    
    var questions = [{
      type    : 'input',
      name    : 'name',
      message : 'Filter Name',
      default : 'myFilter',
      when    : function(answers){
        
        return !filter.name;
        
      }
    }];
    
    return this.prompt(questions).then(function (answers) {
      
      filter.name = answers.name || filter.name;
      
    }.bind(this));
    
  },
  
  writing: function () {
    
    var self = this;
    
    self.composeWith('bookon:component', {
        
        args: [filter.name],

        options: {
          type: "filter",
          path: (filter.path || filter.assets)
        }

    });
   
  }

});