'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _extends2 = require('babel-runtime/helpers/extends');

var _extends3 = _interopRequireDefault(_extends2);

var _bluebird = require('bluebird');

var _bluebird2 = _interopRequireDefault(_bluebird);

var _controllers = require('./controllers');

var _controllers2 = _interopRequireDefault(_controllers);

var _reminders = require('./reminders');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

const meta = require.main.require('./src/meta');

const p = _bluebird2.default.promisify;

const getSettings = p(meta.settings.get);
const setSettings = p(meta.settings.set);


const shallowEqual = (a, b) => {
  const aKeys = Object.keys(a);
  for (const key of aKeys) {
    if (a[key] !== b[key]) {
      return false;
    }
  }
  return true;
};

exports.default = (_ref, callback) => {
  let router = _ref.router;
  let middleware = _ref.middleware;

  (0, _controllers2.default)(router, middleware);

  const defaults = {
    checkingInterval: 1000 * 60 * 5,
    mainPostOnly: false,
    respondIfCanReply: false
  };
  (0, _bluebird.coroutine)(function* () {
    const old = yield getSettings('plugin-calendar');
    const settings = (0, _extends3.default)({}, defaults, old);

    const changed = !shallowEqual(settings, old);
    if (changed) {
      yield setSettings('plugin-calendar', settings);
    }

    yield (0, _reminders.initNotifierDaemon)();
  })().asCallback(callback);
};
//# sourceMappingURL=init.js.map