const { event, sequence, info } = require('../db');

async function prepare (project, query) {
	const events = await event.list(project, query);
	// Get missing shots by default
	const sequences = await sequence.list(project, Object.assign({missing:true}, query));
	const equipment = await info.get(null, "equipment");
	for (const sequence of sequences) {
		const maxTstamp = sequence.ts1_final || sequence.ts1 || +Infinity;
		if (equipment) {
			sequence.equipment = equipment.filter(i => new Date(i.tstamp) <= maxTstamp);
		}
	}
	return {events, sequences};
}

module.exports = prepare;
