let Errors = {
	unknown: [
		'Uh oh! Something went wrong. Please contact a Kaverti staff member for assistance.',
		500
	],
	accountAlreadyCreated: [
		'This account has already been created',
		400
	],
	categoryAlreadyExists: [
		'This category has already been created',
		400
	],
	ReadOnlyMode: [
		'You may not perform this action while in Read-Only mode.',
		400
	],
	LoginRequired: [
		'Due to the nature of this action, a login is required.',
		401
	],
	reCAPTCHA: [
		'Oh uh! You failed the reCAPTCHA score, please try again or contact support! This could be caused because you are operating the API through an unofficial client, CLI application, or reCAPTCHA is blocked by your network administrator or ISP.',
		400
	],
	containsProfanityGeneric: [
		'Please remove profanity from your input',
		400
	],
	deniedWebsiteAccess: [
		'This category has already been created',
		400
	],
	accountDoesNotExist: [
		'This account does not exist',
		400
	],
	botOnlyEndpoint: [
		'This endpoint is only available for bot accounts.'
	],
	invalidCategory: [
		'This category does not exist',
		400
	],
	invalidLoginCredentials: [
		'The username or password provided was incorrect',
		401
	],
	requestNotAuthorized: [
		'You do not have sufficient permissions to do that action.',
		401
	],
	verifyEmail: [
		'You need to verify your email first before you can use Kaverti.',
		401
	],
	invalidToken: [
		'Your QACT (Quick Admin Creation Token) is invalid.',
		401
	],
	featureDisabled: [
		'This feature has been disabled.',
		401
	],
	featureDisabledState: [
		'Administrators can no longer modify state. [Feature Disabled]',
		401
	],
	noLongerHiring: [
		'Sorry! We\'re no longer hiring staff right now.',
		401
	],
	invalidPassKey: [
		'Your PassKey is invalid.',
		401
	],
	noSettings: [
		'This Kaverti node has been incorrectly configured.',
		500
	],
	registrationsDisabled: [
		'Registrations are disabled, Kaverti is using PassKey\'s, if you would like an registration URL, please boost the Kaverti Discord server, If you think this was a mistake please contact an Kaverti administrator.',
		400
	],
	lockedCategory: [
		'This category is locked, only admins can post here, however, you can still respond to existing threads if they aren\'t locked',
		400
	],
	passwordSame: [
		'What\'s the point of changing your password if you\'re going to change it to what it already is.',
		400
	],
	cannotLikeOwnPost: [
		'You can\'t like your own post',
		400
	],
	threadLocked: [
		'Uh, You can\'t reply to a locked thread, bruh.',
		400
	],
	threadTitleMaxLimit: [
		'Thread title is over 50 characters.',
		400
	],
	postRemoved: [
		'The original posters must\'ve deleted their post, so you cannot respond to it!',
		400
	]
}

function processErrors(errorName) {
	let arr = Errors[errorName]

	temp = {}
	temp.name = errorName
	temp.message = arr[0]
	temp.status = arr[1]

	return {
		name: errorName,
		message: arr[0],
		status: arr[1]
	}
}

let ProcessedErrors = {}

for(let errorName in Errors) {
	ProcessedErrors[errorName] = processErrors(errorName)
}

ProcessedErrors.VALIDATION_ERROR = 'VALIDATION_ERROR';

ProcessedErrors.invalidParameter = function (param, message) {
	let punctuatedMessage = '';
	if(message) {
		punctuatedMessage = ': ' + message;
	}

	return {
		name: 'invalidParameter',
		message: `${param} is invalid${punctuatedMessage}`,
		status: 400,
		parameter: param
	};
}

ProcessedErrors.sequelizeValidation = (sequelize, obj) => {
	return new sequelize.ValidationError(obj.error, [
		new sequelize.ValidationErrorItem(
			obj.error,
			'Validation error',
			obj.path,
			obj.value
		)
	])
}

module.exports = ProcessedErrors
