/**
 * Base class for all objects on this library.
 */
module.exports = new Class({
	Extends: Vn.Object

	/**
	 * Gets if the object is ready to be rendered.
	 *
	 * @param {Object} params The query parameters
	 * @return {boolean} %true if the object is ready, %false otherwise
	 */
	,isReady() {
		return true;
	}

	/**
	 * Through the query looking for containers.
	 *
	 * @return {Array} An array with the names of the found parameters
	 */
	,findHolders() {}
	
	/**
	 * Renders the object as an SQL string.
	 *
	 * @param {Object} params The params used to render the object
	 * @return {string} The SQL string
	 */
	,render() {}
	
	/**
	 * Renders an objects array.
	 *
	 * @param {Array} list The objects array
	 * @param {Object} params The parameters
	 * @return {string} The rendered SQL string
	 */
	,renderList(list, params) {
		var sql = '';

		list.forEach(function(item) {
			sql += item.render(params);
		})

		return sql;
	}

	/**
	 * Renders an objects array using a separator.
	 *
	 * @param {Array} list The objects array
	 * @param {Object} params The parameters
	 * @param {String} separator The separator between items
	 * @return {string} The rendered SQL string
	 */
	,renderListWs(list, params, separator) {
		var sql = '';

		list.forEach(function(item, i) {
			if (i > 0)
				sql += separator;
			sql += item.render(params);
		})

		return sql;
	}

	/**
	 * Renders a quoted SQL identifier.
	 *
	 * @param {String} identifier The identifier
	 * @return {string} The quoted identifier
	 */
	,renderIdent(identifier) {
		return '`'+ identifier +'`';
	}
	
	/**
	 * Renders a quoted SQL identifier.
	 *
	 * @param {String} identifier The identifier
	 * @return {string} The quoted identifier
	 */
	,renderPreIdent(identifier) {
		if (identifier)
			return this.renderIdent(identifier) +'.';
		else
			return '';
	}

	/**
	 * Renders the object if it's defined.
	 *
	 * @param {String} prefix The rendered string prefix
	 * @return {string} The rendered object with its prefix
	 */
	,renderIfSet(object, prefix, params) {
		if (object)
			return ' '+ prefix +' '+ object.render(params);
		else
			return '';
	}
});
