"use strict";

module.exports = {
	setUp: function () {

		var Database = require("./Database.js");
		var settings = require("../../settings.js");

		this.util = require("../utils/util.js");
		this.Item = require("./Item.js");
		this.database = new Database();
		
		console.log("Generating database");
		this.util.fillDatabase(this.database, settings.getSetting("general.maxBuckets"));

		console.log("Buckets: " + this.database.getTotalBuckets());
		console.log("Collections: " + this.database.getTotalCollections());
		console.log("Keys: " + this.database.getTotalKeys());

	},
	tearDown: function () {
		this.database.destroy();
	},
	applyBenchmarks: function(suite) {

		suite.add('Database.getTotalBuckets', function() { this.database.getTotalBuckets();}.bind(this));
		suite.add('Database.getTotalCollections', function() { this.database.getTotalCollections(); }.bind(this));
		suite.add('Database.getTotalKeys', function() { this.database.getTotalKeys(); }.bind(this));
		suite.add('Database.fetchAll', function() { this.database.fetchAll(); }.bind(this));
		suite.add('Database.fetchBucket', function() { this.database.fetchBucket(1); }.bind(this));
		suite.add('Database.fetchCollection', function() { this.database.fetchCollection(1, "users"); }.bind(this));
		suite.add('Database.fetchItem', function() { this.database.fetchItem(1, "users", "1"); }.bind(this));
		suite.add('Database.fetchValue', function() { this.database.fetchValue(1, "users", "1"); }.bind(this));
		suite.add('Database.fetchValueUpdateAccess', function() { this.database.fetchValueUpdateAccess(1, "users", "1"); }.bind(this));
		suite.add('Database.fetchBucketNames', function() { this.database.fetchBucketNames(); }.bind(this));
		suite.add('Database.fetchCollectionNames', function() { this.database.fetchCollectionNames(1); }.bind(this));
		suite.add('Database.fetchKeyNames', function() { this.database.fetchKeyNames(1, "users"); }.bind(this));
		suite.add('Database.addItem', function() { this.database.addItem("1", "users", "1", new this.Item('Scott'), 0); }.bind(this));

	}
};