"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) {
	const isObjectType = require("../validators/operations/is-object-type")(operations);
	const isExpression = require("../validators/operations/is-expression")(operations);
	const isWhereObject = require("../validators/operations/is-where-object")(operations);
	
	return function where(_predicates) {
		let [ predicates ] = validateArguments(arguments, {
			predicates: [ required, either([
				[ isObjectType("sqlExpression") ],
				[ isExpression ], // FIXME: Make sure to document that this is what is to be used instead of two-argument WHERE syntax
				[ isWhereObject ]
			])]
		});

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