"use strict";

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

require("./blackout");

/**
 * This file is for testing this library only
 */

exports.handler = (() => {
	var _ref = _asyncToGenerator(function* (event, context, callback) {

		try {

			// Init Blackout
			yield blackout.initAsync(event, callback);
			//blackout.logPromises();
			//blackout.logLocks();

			// -------------------------------------------- Do stuff

			// ------------------------- Generate new squad

			let doDelete = false;

			let params = {
				clubId: '6b583141-bd0b-4ee6-a661-c58f5aad2b49',
				managerId: '25c75ace-1ca8-40b5-840f-98bf796406af'
			};

			if (doDelete) {

				let { data: oldSquad } = yield blackout.db.getAllAsync({
					table: 'Players',
					group: { field: 'Club', value: params.clubId, index: 'Club' },
					attrs: ['Id', 'Club']
				});

				if (oldSquad.length) {
					yield blackout.db.deleteItemsAsync({
						table: 'Players',
						items: oldSquad,
						groups: {
							Club: 'Club'
						}
					});
				}
			} else {

				console.time('generateSquad');
				yield blackout.genesis.createAndStoreStarterSquadAsync(params);
				console.timeEnd('generateSquad');
			}

			// -------------------------------------------- End stuff

			console.log('Done');
			blackout.complete();
		} catch (err) {
			blackout.complete(err);
		}
	});

	return function (_x, _x2, _x3) {
		return _ref.apply(this, arguments);
	};
})();
//# sourceMappingURL=index.js.map