"use strict";

const { validateOptions } = require("@validatem/core");
const required = require("@validatem/required");
const oneOf = require("@validatem/one-of");
const arrayOf = require("@validatem/array-of");
const isBoolean = require("@validatem/is-boolean");

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

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

	return function _arrayOf(_options) {
		let { type, items, canBeParameterized } = validateOptions(arguments, {
			type: [ required, oneOf([ "anyOf", "allOf" ]) ],
			canBeParameterized: [ required, isBoolean ],
			items: [ required, arrayOf(isValueExpression) ]
		});

		return node({
			type: "_arrayOf",
			canBeParameterized: canBeParameterized,
			listType: type,
			items: items
		});
	};
};
