"use strict";

// Source maps for ES7 compilation

require('source-map-support').install();

// Promises
global.Promise = require("bluebird");

// Blackout sub-APIs
var dynamo = Promise.promisifyAll(require("./lib/dynamo"));
var db = Promise.promisifyAll(require("./lib/db"));
var settings = Promise.promisifyAll(require("./lib/settings"));
var sqs = Promise.promisifyAll(require("./lib/sqs"));
var stats = Promise.promisifyAll(require("./lib/stats"));
var genesis = Promise.promisifyAll(require("./lib/genesis"));
var playerLib = Promise.promisifyAll(require("./lib/player"));

// Blackout modules
var setup = require("./lib/setup");
var helpers = require("./lib/helpers");
var errors = require("./lib/errors");
var complete = require("./lib/complete");
var locking = require("./lib/locking");
var date = require("./lib/date");

// Finally

global.blackout = Promise.promisifyAll(Object.assign({

	/**
  * Reminder: module variables can be reused between lambda calls
  * Please keep this in mind. Thanks.
  */
	dynamo: dynamo,
	db: db,
	settings: settings,
	queue: sqs,
	stats: stats,
	genesis: genesis,
	playerLib: playerLib,

	/**
  * Flags
  */
	isAPI: false, // Should be set to true if this is the API

	init(event, callback, callbackOnceConnected) {

		this.setup(event, callback);

		// For logging input event
		//this.log('event',event);

		// Ensure redis is connected before continuing
		this.connectRedis(err => {

			if (err) {
				// We can't survive without redis since we need it for locking
				this.complete(err);
			} else {

				callbackOnceConnected();
			}
		});

		// Automatically call callback once all callbacks are complete
		this.autoComplete();
	}

}, setup, helpers, errors, complete, locking, date));

module.exports = blackout;
//# sourceMappingURL=blackout.js.map