const { DEBUG, ERROR } = require('DOUGAL_ROOT/debug')(__filename);
const { setSurvey, transaction } = require('../connection');

async function post (projectId, payload, opts = {}) {

	const p = payload; // Shorter
	const client = await setSurvey(projectId);
	try {

		const text = `
			INSERT
			INTO event_log (tstamp, sequence, point, remarks, labels, meta)
			VALUES ($1, $2, $3, replace_placeholders($4, $1, $2, $3), $5, $6);
		`;
		const values = [ p.tstamp, p.sequence, p.point, p.remarks, p.labels, p.meta ];

		DEBUG("Inserting new values: %O", values);
		await client.query(text, values);
	} catch (err) {
		err.origin = __filename;
		throw err;
	} finally {
		client.release();
	}

	return;
}

module.exports = post;
