"use strict";

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

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

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

	return function alias(_name, _expression) {
		let [ name, expression ] = validateArguments(arguments, {
			name: [ required, isField ],
			// FIXME: Make more strict to only accept column references, and expect the user to use compute for the rest (which should internally use an _expression type or so to pass into alias, during set-collapse-by-field)
			expression: [ required, isValueExpression ]
		});

		return node({ type: "alias", field: name, expression: expression });
	};
};
