const smash = require('../../../../../smash');
const errorUtil = smash.errorUtil();
const { isString, typeError, readable, fullName, validateSiblings, validateChild, getLatestFromNames, loadCurrentValue } = require("../../util/ruleUtil");
const { STRING, TYPE, CAST_TO, MATCH, DEFAULT, VALIDATE, MIN, MAX, ERRORS, OPTIONAL } = require("../../constant");

const depth = 1;
const config = {
	userInput: {
		siblings: [
			{ name: TYPE, match: "^(" + [STRING].join("|") + ")$" },
			{ name: CAST_TO },
			{ name: DEFAULT },
			{ name: VALIDATE },
			{ name: OPTIONAL },
			{ name: MIN },
			{ name: MAX },
		],
		children: { types: [STRING] },
	},
};

module.exports = {
	name: MATCH,
	priority: 70,

	validate,
	execute,
	config,
};

function execute({ rule, data }) {
	return new Promise((resolve, reject) => {
		loadCurrentValue(data);
		const regexp = new RegExp(rule.current.value);
		if (regexp.test(data.current.value)) {
			resolve(true);
		} else {
			reject(errorUtil.badRequestError("Invalid body", { type: ERRORS.MATCH, reason: ERRORS.REASON_MATCH, name: data.current.name, expected: rule.current.value, given: data.current.value }));
		}
	});
}

function validate({ current, parents, ruleConfig }) {
	const { siblings, children } = getLatestFromNames(config, parents, depth, MATCH);
	validateSiblings({ siblings, current, parents, ruleConfig });
	if (isString(current)) {
		const child = current;
		validateChild({ child, children, parents, current, ruleConfig });
		try {
			new RegExp(child.value);
			return true;
		} catch (error) {
			throw new Error("Error in rule " + readable(ruleConfig) + " => '" + fullName(parents, current) + "': " + error.message);
		}
	}
	throw typeError({ current, ruleConfig, expected: STRING });
}

@@ -638,16 +638,211 @@
  %7D,%0A%09%7D,%0A
+%09content: %7B%0A%09%09siblings: %5B%0A%09%09%09%7B name: TYPE, match: %22%5E(%22 + %5BSTRING%5D.join(%22%7C%22) + %22)$%22 %7D,%0A%09%09%09%7B name: CAST_TO %7D,%0A%09%09%09%7B name: DEFAULT %7D,%0A%09%09%09%7B name: VALIDATE %7D,%0A%09%09%5D,%0A%09%09children: %7B types: %5BSTRING%5D %7D,%0A%09%7D,%0A
 %7D;%0A%0Amodu
@@ -885,17 +885,16 @@
 ty: 70,%0A
-%0A
 %09validat

Add match under content property