"use strict";

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

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

module.exports = function count(operations) {
	const isPossiblyForeignColumn = require("../validators/operations/is-possibly-foreign-column")(operations);

	return function sum(_column) {
		let [ column ] = validateArguments(arguments, {
			column: [ required, isPossiblyForeignColumn ]
		});

		return node({
			type: "aggregrateFunction",
			functionName: "sum",
			args: [ column ]
		});
	};
};
