"use strict";

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

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

module.exports = function (operations) {
	const isCondition = require("../validators/operations/is-condition")(operations);
	const isPossiblyForeignColumn = require("../validators/operations/is-possibly-foreign-column")(operations);
	
	return function expression(_options) {
		let { left, condition } = validateOptions(arguments, {
			left: [ required, isPossiblyForeignColumn ], // FIXME: allow sqlExpression and such
			condition: [ required, isCondition ]
		});

		// FIXME/MARKER: Rename to 'assert'?
		
		return node({
			type: "expression",
			left: left,
			condition: condition
		});
	};
};
