/* */ 
{
  var _ns_ = {
    id: 'atomita.http.resource',
    doc: 'base of the resource class.'
  };
  var lodash = require('lodash');
  var atomita_http_request = require('./request');
  var request = atomita_http_request;
}
var defaults = {
  params: {},
  actions: {
    'get': {'method': 'GET'},
    'save': {'method': 'POST'},
    'query': {
      'method': 'GET',
      'isArray': true
    },
    'update': {'method': 'PUT'},
    'remove': {'method': 'DELETE'},
    'delete': {'method': 'DELETE'}
  },
  options: {'mergeActions': true}
};
var resource = function resource(url, vars) {
  return function() {
    var resourceø1 = function resource() {
      var args = Array.prototype.slice.call(arguments, 0);
      return Resource.apply(this, args);
    };
    var varsø2 = lodash.defaults(vars, defaults);
    var paramsø1 = varsø2.params || defaults.params;
    var optionsø1 = lodash.defaults(varsø2.options || {}, defaults.options);
    var actionsø1 = lodash.defaults(varsø2.actions || {}, optionsø1.mergeActions ? defaults.actions : {});
    var urlBuilderø1 = buildUrl(url, paramsø1);
    resourceø1.prototype = lodash.create(Resource.prototype, {
      value: resourceø1,
      enumerable: false,
      writable: true,
      configurable: true
    });
    defineActions(resourceø1.prototype, actionsø1, urlBuilderø1, paramsø1);
    defineActions(resourceø1, actionsø1, urlBuilderø1, paramsø1);
    return resourceø1;
  }.call(this);
};
module.exports = resource;
var buildUrl = function buildUrl(url, params) {
  return function() {
    var builderø1 = function urlBuilder(url, params) {
      return url;
    };
    url.replace(RegExp('(?::)([^:/]+)', 'g'), function(place, k, i) {
      return function() {
        var orgBuilderø1 = builderø1;
        return builderø1 = function urlBuilder(url, params) {
          return orgBuilderø1(url.slice(0, i) + (lodash.has(params, k) ? lodash.get(params, k) : place) + url.slice(i + place.length), params);
        };
      }.call(this);
    });
    return function(params) {
      return builderø1(url, params);
    };
  }.call(this);
};
var defineActions = function defineActions(resource, actions, urlBuilder, classParams) {
  return function loop() {
    var recur = loop;
    var keysø1 = lodash.keysIn(actions);
    do {
      recur = keysø1.length ? function() {
        var methodNameø1 = lodash.first(keysø1);
        var actionø1 = actions[methodNameø1];
        resource[methodNameø1] = function actionMethod(params, options) {
          return function() {
            var paramsø2 = lodash.defaults(params || {}, this instanceof Resource ? this : {}, actionø1.params || {}, classParams);
            var optionsø2 = lodash.defaults(options || {}, actionø1);
            0 <= lodash.indexOf(['GET', 'HEAD'], actionø1.method.toUpperCase()) ? optionsø2.query = lodash.defaults(optionsø2.query || {}, paramsø2) : void 0;
            return request(actionø1.method, urlBuilder(paramsø2), paramsø2, optionsø2, this instanceof Resource ? this.constructor : this);
          }.call(this);
        };
        return loop[0] = lodash.slice(keysø1, 1), loop;
      }.call(this) : void 0;
    } while (keysø1 = loop[0], recur === loop);
    return recur;
  }.call(this);
};
var Resource = function Resource(propeties, response) {
  return function() {
    var propetiesø2 = propeties || {};
    var responseø2 = response || {};
    var resourceø1 = function resource() {
      return lodash.extend(this, propetiesø2);
    };
    this.response = responseø2;
    resourceø1.prototype = this;
    return new resourceø1();
  }.call(this);
};
