"use strict";

const { validateArguments } = require("@validatem/core");
const required = require("@validatem/required");

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

module.exports = function (operations) {
	const isPredicateList = require("../validators/operations/is-predicate-list")(operations);

	return function anyOf(_items) {
		let [ items ] = validateArguments(arguments, {
			items: [ required, isPredicateList ]
		});
		
		if (items.type === "values") {
			return node({
				type: "anyOfValues",
				items: items.value
			});
		} else if (items.type === "conditions") {
			return node({
				type: "anyOfConditions",
				items: items.value
			});
		} else if (items.type === "expressions") {
			return node({
				type: "anyOfExpressions",
				items: items.value
			});
		} else {
			unreachable(`Invalid tagged type '${items.type}'`);
		}
	};
};
