/**
 * Database Ajax requests
 * 
 * @category    Database
 * @package     ATProcessor
 * @author      Sam Meredith <sam@aandtinstruments.com>
 * @version     0.1
 */

 /**
 * Delete an entire section from the database
 * @param {string} section 
 */
function deleteSection(section) {
	return $.ajax({
		type: 'POST',
		url: '/database.php',
		data: {action: 'deleteSection', section: section}
	})
}

/**
 * Reads an entire section from the database
 * @param {string} section 
 * @param {bool} toLower 
 */
function readSection(section, toLower = true) {
	return $.ajax({
		type: 'POST',
		url: '/database.php',
		data: {action: 'readSection', section: section, toLower: toLower}
	});
}

/**
 * Reads the value for a given section,key pair
 * @param {String} section 
 * @param {String} key 
 */
function readSingle(section, key) {
	return $.ajax({
		type: 'POST',
		url: '/database.php',
		data: {action: 'read', section: section, key: key}
	});
}

/**
 * Post a single field to database
 * @param {string} section The section to update
 * @param {string} key The key to update
 * @param {string} value The value to update
 * @param {string} category The category to update
 * @return {jqXHR} XMLHttpRequest response of $.ajax() query
 **/
function writeSingle(section, key, value, category) {
	return $.ajax({
		type: 'POST',
		url: '/database.php',
		data: {action: 'write', section: section, key: key, value: value, category: category}
	});
}

/**
 * Post fields for writing to database
 * @param [{'section' : , 'key' : , 'value'}] inputs Array of triplets to write
 * @param {string} category The category to update processor
 * @return {jqXHR} XMLHttpRequest response of $.ajax() query
 **/
function writeToDatabase(inputs, category) {
	return $.ajax({
		type: 'POST',
		url: '/database.php',
		data: {action: 'writeArray', data: JSON.stringify(inputs), category: category}
	});
}