<?php

namespace App\Utils\Db\ManageRecords;

class Delete extends GeneralAbstract
{

	/**
	 * The populating DB table name (usually report).
	 * @var string
	 */
	protected $populatingTableName;


	/**
	 * Sets the report table name.
	 * @param string $populatingTableName
	 */
	public function __construct($populatingTableName)
	{
		if (!$populatingTableName) {
			throw new \Exception('You must set the populating table name.');
		}
		$this->populatingTableName	= $populatingTableName;
	}


	public function getFullSQL() :?array
	{

		if (!$this->filters) {
			throw new \Exception('You did not define any filters when using `DELETE`.');
		}

		$bindVars = [];

		// add UPDATE clause
		$sql = "DELETE FROM `{$this->populatingTableName}`";

		// add WHERE
		$whereSQL = $this->getSQL_where();
		if ($whereSQL['sql']) {
			$sql .= " WHERE ".$whereSQL['sql'];
			$bindVars = $whereSQL['bindVars'];
		}

		return [ 'sql'=>$sql, 'bindVars'=>$bindVars ];

	}

}
