"use strict";

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

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

module.exports = function (operations) {
	return function resultExists(_expression) {
		const isExpression = require("../../validators/operations/is-expression")(operations);
		const isRelation = require("../../validators/operations/is-relation")(operations); // FIXME: More specific type?
		// MARKER: Finish this

		let [ expression ] = validateArguments(arguments, {
			expression: [ required, either([ isExpression, isRelation ]) ]
		});

		return node({
			type: "index",
			expression: expression
		});
	};
};
