"use strict";

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

const node = require("../../ast-node");
const isCollectionName = require("../../validators/is-collection-name");

module.exports = function (operations) {
	const isObjectType = require("../../validators/operations/is-object-type")(operations);

	return function define(_name, _value) {
		// NOTE: `define` essentially creates a virtual collection, which means that the name should comply with the usual collection naming rules
		let [ name, value ] = validateArguments(arguments, {
			name: [ required, isCollectionName ],
			value: [ required, isObjectType("relation") ] // FIXME: Support subqueries
		});

		return node({
			type: "define",
			name: name,
			value: value
		});
	};
};
