'use strict';

var path = require('path');
var utils = require('agentia-utilities');
var changeCase = require('agentia-change-case');
var Asset = require('./asset');
var helpers = require('./helpers');

var registerModule = function registerModule(id, modulePath, injectable) {
  var asset;

  helpers.checkMinArgs(arguments, 1);
  helpers.checkMustBeString(id, 'id');

  if (arguments.length === 1) {
    modulePath = id;
    id = changeCase.camel(path.basename(modulePath, '.js'));
  }

  if (arguments.length === 2 && utils.isBoolean(modulePath)) {
    injectable = modulePath;
    modulePath = id;
    id = changeCase.camel(path.basename(modulePath, '.js'));
  }

  helpers.checkMustBeString(modulePath, 'modulePath');

  if (!utils.isBoolean(injectable)) {
    injectable = false;
  }

  asset = new Asset(id, modulePath, {
    module: true,
    injectable: injectable
  });

  this._assets[id] = asset;

  return this;
};

module.exports = registerModule;

@@ -275,22 +275,8 @@
 ) %7B%0A
-  var asset;%0A%0A
   he
@@ -776,16 +776,27 @@
 %0A%0A  
-a
+this.registerA
 sset
- = 
+(
 new 
@@ -872,37 +872,9 @@
   %7D)
-;%0A%0A  this._assets%5Bid%5D = asset
+)
 ;%0A%0A 

refactor code that registers the asset