"use strict";

const required = require("@validatem/required");
const isString = require("@validatem/is-string");
const arrayOf = require("@validatem/array-of");

const isTimelineEvent = require("../is-timeline-event");
const isStateEvent = require("../is-state-event");
const optionalArray = require("../optional-array");

module.exports = function isMessagesResponse(strict = false, extraFields = {}) {
	// FIXME: Expand validation rules affected by 'strict' setting? eg. allowing extra properties in the messages response itself
	let isTimelineList = arrayOf([ required, isTimelineEvent(strict, extraFields) ]);
	let isStateList = arrayOf([ required, isStateEvent(strict, extraFields) ]);
	
	return {
		start: [ required, isString ],
		end: [ isString ],
		chunk: optionalArray(isTimelineList),
		state: optionalArray(isStateList)
	};
};
