const { setSurvey, pool } = require('../connection');
const { create } = require('./create');

/*
 * Creating a new project consists of these steps:
 *
 * - Check that the payload is well formed and includes all required items.
 *   If not, return 400.
 * - Check if the id already exists. If it does, return 409.
 * - Figure out what the next schema name is going to be (survey_XXX).
 * - Read the SQL template from $DOUGAL_ROOT/etc/db/schema-template.sql and
 *   replace the `_SURVEY__TEMPLATE_` and `_EPSG__CODE_` placeholders with
 *   appropriate values.
 * - Apply the resulting SQL.
 * - Add the appropriate entry into public.projects
 * - Add the survey definition details (the request's payload) into the
 *   database (or create a YAML file under $DOUGAL_ROOT/etc/surveys?)
 * - Return a 201 with the survey definition as the payload.
 */

async function post (payload) {
	try {
		return await create(payload);
	} catch (err) {
		throw err;
	}
}

module.exports = post;
