"use strict";

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

const { validateArguments } = require("@validatem/core");
const required = require("@validatem/required");
const forbidRemoteFields = require("../../validators/forbid-remote-fields");

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

	return function defaultTo(_value) {
		let [ value ] = validateArguments(arguments, {
			value: [ required, isValueExpression, forbidRemoteFields ] // FIXME: Forbid aggregrate functions?
		});

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