"use strict";

const matchValue = require("match-value");

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

module.exports = function makeIndexObject(fieldsResult, properties) {
	if (fieldsResult.type === "local") {
		return node({
			type: "localIndex"
		});
	} else {
		let isComposite = matchValue(fieldsResult.type, {
			single: false,
			composite: true
		});

		return node({
			type: "index",
			isComposite: isComposite,
			field: (isComposite === false) ? fieldsResult.value : undefined,
			fields: (isComposite === true) ? fieldsResult.value : undefined,
			... properties
		});
	}
};
