var keylime = require('./');
var _ = require('lodash');

var KeylimePost = keylime('KeylimePost')
    .attr('draft', true)
    .attr('title', '')
    .attr('tags', [])
    .attr('date', function createDate() {
      return Date.now();
    });

var HybridPost = keylime(function HybridPost(title, options) {
      this.keylime.init(this, options);
      this.title = title;
    })
    .attr('title', '')
    .attr('draft', true)
    .attr('tags', [])
    .attr('date', function() {
      return Date.now();
    });

var plainAttrs = {
  title: '',
  tags: [],
  draft: true,
  date: function createDate() {
    return Date.now();
  }
};

function BarePost(params) {
  this.title = params.title || '';
  this.tags = params.tags || [];
  this.draft = params.draft || true;
  this.date = params.date || Date.now();
}

function PlainPost(params) {
  var value;

  for (var attrName in plainAttrs) {
    if (plainAttrs.hasOwnProperty(attrName)) {
      if (params && params[attrName] !== undefined) {
        value = params[attrName];
      } else {
        value = plainAttrs[attrName];
      }

      if (typeof value === 'function') {
        this[attrName] = value();
      } else {
        this[attrName] = value;
      }
    }
  }
}

suite('creating instances with \'new\'', function() {
  bench('bare post', function() {
    new BarePost({title: 'New Post'});
  });

  bench('plain constructor', function() {
    new PlainPost({title: 'New Post'});
  });

  bench('keylime', function() {
    new KeylimePost({title: 'New Post'});
  });

  bench('hybrid', function() {
    new HybridPost('New Post');
  });
});

@@ -1600,12 +1600,458 @@
 ;%0A  %7D);%0A%7D);%0A
+%0Asuite('attribute counts', function() %7B%0A  var Jedi0 = keylime('Jedi');%0A  var Jedi3 = keylime('Jedi').attr('one', 1).attr('two', 2).attr('three', 3);%0A  var Jedi5 = keylime('Jedi').attr('one', 1).attr('two', 2).attr('three', 3).attr('four', 4).attr('five', 5);%0A%0A  bench('0 attributes', function() %7B%0A    new Jedi0();%0A  %7D);%0A%0A  bench('3 attributes', function() %7B%0A    new Jedi3();%0A  %7D);%0A%0A  bench('5 attributes', function() %7B%0A    new Jedi5();%0A  %7D);%0A%7D);%0A

update benchmarks