"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 isConditionValue = require("../validators/operations/is-condition-value")(operations);

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

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