const { Configuration } = require('@schul-cloud/commons');
const reqlib = require('app-root-path').require;

const {} = reqlib('src/errors');
const eventListener = require('./eventListener');
const producer = require('./producer');
const consumer = require('./consumer');
const { messengerSchoolSyncService, messengerSchoolSyncHooks } = require('./services/schoolSyncService');
const { messengerTokenService, messengerTokenHooks } = require('./services/messengerTokenService');

module.exports = (app) => {
	if (Configuration.get('FEATURE_MATRIX_MESSENGER_ENABLED')) {
		if (!Configuration.get('FEATURE_RABBITMQ_ENABLED')) throw new GeneralError('messenger requires rabbitMQ');

		app.use('schools/:schoolId/messengerSync', messengerSchoolSyncService);
		app.service('schools/:schoolId/messengerSync').hooks(messengerSchoolSyncHooks);

		app.use('messengerToken', messengerTokenService);
		app.service('messengerToken').hooks(messengerTokenHooks);

		app.configure(eventListener);
		app.configure(producer.setup);
		app.configure(consumer);
	}
};

@@ -109,16 +109,30 @@
 %0Aconst %7B
+ GeneralError 
 %7D = reql

Add require of generalerror