"use strict";

const { validateArguments } = require("@validatem/core");
const required = require("@validatem/required");
const arrayOf = require("@validatem/array-of");

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

module.exports = function (operations) {
	const isSelectableField = require("../validators/operations/is-selectable-field")(operations);

	return function onlyFields(_fields) {
		let [ fields ] = validateArguments(arguments, {
			fields: [ required, arrayOf([ required, isSelectableField ]) ]
		});

		return node({ type: "onlyFields", fields: fields });
	};
};
