"use strict";

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

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

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

	return function defaultTo(_value) {
		let [ value ] = validateArguments(arguments, {
			value: [ required, isLocalValueExpression ]
		});

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