"use strict";

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

const makeIndexObject = require("./_make-index-object");

module.exports = function (operations) {
	const isIndexFields = require("../../validators/operations/is-index-fields")(operations);
	const isObjectType = require("../../validators/operations/is-object-type")(operations);

	return function unique(_fields, _clauses) {
		let [ fields, clauses ] = validateArguments(arguments, {
			fields: isIndexFields,
			clauses: [ defaultTo([]), arrayOf(isObjectType("where")) ]
		});

		return makeIndexObject(fields, {
			clauses: clauses,
			indexType: "unique"
		});
	};
};
