export function unknown(error?: Error): Response {
	if (Deno.env.get('TRACE_ERROR_RESPONSES')) {
		console.trace(error ?? 'unknown error');
	}
	return Response.json({
		error: {
			message: error?.message ?? 'Unknown Error',
			cause: error?.cause ?? 'unknown_error',
			stack: Deno.env.get('TRACE_ERROR_RESPONSES') ? error?.stack ?? '' : null
		}
	}, {
		status: 500
	});
}

export function not_found(): Response {
	if (Deno.env.get('TRACE_ERROR_RESPONSES')) {
		console.trace('not_found');
	}
	return Response.json({
		error: {
			message: 'Not found.',
			cause: 'not_found'
		}
	}, {
		status: 404
	});
}

export function conflict(): Response {
	if (Deno.env.get('TRACE_ERROR_RESPONSES')) {
		console.trace('conflict');
	}
	return Response.json({
		error: {
			message: 'Conflict - this resource already exists.',
			cause: 'conflict'
		}
	}, {
		status: 409
	});
}

export function permission_denied(): Response {
	if (Deno.env.get('TRACE_ERROR_RESPONSES')) {
		console.trace('permission_denied');
	}
	return Response.json({
		error: {
			message: 'Permission denied.',
			cause: 'permission_denied'
		}
	}, {
		status: 400
	});
}

export function append_only_events(): Response {
	if (Deno.env.get('TRACE_ERROR_RESPONSES')) {
		console.trace('append_only_events');
	}
	return Response.json({
		error: {
			message: 'This server does not allow modifying events.',
			cause: 'append_only_events'
		}
	}, {
		status: 400
	});
}
