"use strict";

const { validateOptions } = require("@validatem/core");
const required = require("@validatem/required");
const oneOf = require("@validatem/one-of");
const either = require("@validatem/either");

const node = require("../ast-node");

module.exports = function (operations) {
	const isInternalArrayType = require("../validators/operations/is-internal-array-type")(operations);
	const isValueExpression = require("../validators/operations/is-value-expression")(operations);

	return function _condition(_options) {
		let { type, expression } = validateOptions(arguments, {
			type: [ required, oneOf([ "lessThan", "moreThan", "equals" ]) ],
			expression: [ required, either([ isValueExpression, isInternalArrayType ]) ]
		});

		return node({
			type: "condition",
			conditionType: type,
			expression: expression
		});
	};
};
