"use strict";

const { validateOptions } = require("@validatem/core");
const either = require("@validatem/either");
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 isConditionValue = require("../validators/operations/is-condition-value")(operations);
	const isObjectType = require("../validators/operations/is-object-type")(operations);

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

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