"use strict";

const { validateArguments } = require("@validatem/core");
const arrayOf = require("@validatem/array-of");
const defaultTo = require("@validatem/default-to");
const required = require("@validatem/required");
const isString = require("@validatem/is-string");

const isLiteralValue = require("../validators/is-literal-value");
const node = require("../ast-node");

module.exports = function (_operations) {
	return function unsafeSQL(_sql, _parameters) {
		// FIXME: Wrap in parens within an alias, when stringifying?
		let [ sql, parameters ] = validateArguments(arguments, {
			sql: [ required, isString ],
			parameters: [ defaultTo([]), arrayOf(isLiteralValue) ]
		});

		return node({ type: "sqlExpression", sql, parameters });
	};
};
