"use strict";

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

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

module.exports = function count(operations) {
	const isPossiblyRemoteField = require("../validators/operations/is-possibly-remote-field")(operations);

	return function sum(_field) {
		let [ field ] = validateArguments(arguments, {
			field: [ required, isPossiblyRemoteField ]
		});

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