const rolesModel = require('../../../../../src/services/role/model.js');
const { userModel } = require('../../../../../src/services/user/model.js');
const accountModel = require('../../../../../src/services/account/model.js');

const app = require('../../../../../src/app');

const deleteUser = async (email = 'foo@bar.baz') => {
	await userModel.deleteOne({ email });
	await accountModel.deleteOne({ username: email });
};

const createClass = async ([gradeLevelName, className, schoolId]) => {
	const gradeLevels = await app.service('gradeLevels').find({
		query: {
			name: gradeLevelName,
		},
		paginate: false,
	});
	let classObject;
	if (gradeLevels.length > 0) {
		classObject = {
			schoolId,
			nameFormat: 'gradeLevel+name',
			gradeLevel: gradeLevels[0]._id,
			name: className,
		};
	} else {
		classObject = {
			schoolId,
			nameFormat: 'static',
			name: className,
		};
	}
	await app.service('classes').create(classObject);
};

const findClass = async ([gradeLevelName, className]) => {
	const gradeLevels = await app.service('gradeLevels').find({
		query: {
			name: gradeLevelName,
		},
		paginate: false,
	});
	let classObject;
	if (gradeLevels.length > 0) {
		[classObject] = await app.service('classes').find({
			query: {
				nameFormat: 'gradeLevel+name',
				gradeLevel: gradeLevels[0]._id,
				name: className,
			},
			paginate: false,
		});
	} else {
		[classObject] = await app.service('classes').find({
			query: {
				nameFormat: 'static',
				name: className,
			},
			paginate: false,
		});
	}
	return classObject;
};

const deleteClass = async ([gradeLevelName, className]) => {
	const classObject = await findClass([gradeLevelName, className]);
	await app.service('classes').remove(classObject._id);
};

class MockEmailService {
	constructor(eventHandler) {
		this.eventHandler = eventHandler;
	}

	create({
		headers, email, subject, content,
	}, params) {
		this.eventHandler({ subject, content });
		return Promise.resolve();
	}
}

module.exports = {
	deleteUser,
	createClass,
	findClass,
	deleteClass,
	MockEmailService,
};

@@ -1,77 +1,4 @@
-const rolesModel = require('../../../../../src/services/role/model.js');%0A
 cons
@@ -1766,26 +1766,8 @@
 te(%7B
-%0A%09%09headers, email,
  sub
@@ -1779,19 +1779,17 @@
  content
-,%0A%09
+ 
 %7D, param
@@ -1831,16 +1831,24 @@
  content
+, params
  %7D);%0A%09%09r

Remove unnecessary code