// Generated by CoffeeScript 1.8.0
(function() {
  var Trunk;

  Trunk = (function() {
    function Trunk(configurator, obj) {
      var Template;
      this.configurator = configurator;
      Template = configurator.template;
      this.user = Template['users']('__user', obj);
      this.setName(this.user.getName());
    }

    Trunk.prototype.save = function(callback) {
      this._appendContextForTrunk(function() {
        return console.log('trunk');
      });
      return this._appendObjectToUsersConf(callback);
    };

    Trunk.prototype.setName = function(name) {
      return this.name = 'trunk_' + name;
    };

    Trunk.prototype._appendObjectToUsersConf = function(callback) {
      var users_conf;
      users_conf = this.configurator.files['users.conf'];
      users_conf[this.name] = this.user.getAttributes();
      return this.configurator.saveFile('users.conf', callback);
    };

    Trunk.prototype._appendContextForTrunk = function(callback) {
      var App, D, context, extensions_conf;
      extensions_conf = this.configurator.files['extensions.conf'];
      D = this.configurator.dialplan;
      App = D.Application;
      context = new D.Context(this.name);
      context.append([new D.Extension('s').append(App.Dial('SIP/gate')), new D.Include('international_calls')]);
      extensions_conf[this.name] = context.makeObject();
      return this.configurator.saveFile('extensions.conf', callback);
    };

    return Trunk;

  })();

  module.exports = Trunk;

}).call(this);
