<?php
session_start();
require_once '../utils/errorhandler.php';
require_once '../utils/response.php';
require_once '../model/dbclass.php';
require_once '../model/model.php';
require_once '../model/Property.php';

if ($_SESSION['wuseremail'] === null || !isset($_SESSION['wuseremail'])) {
     exit(badRequest(204,'Invalid session data. Proceed to login'));
}

$property = new Property();

$status = (isset($_POST["status"]) && $_POST["status"] !== "") ? $_POST["status"] : "%";
//$startdate = (isset($_POST["startdate"]) && $_POST["startdate"] !== "") ? $_POST["startdate"] : date('Y-m-d');
//$enddate = (isset($_POST["enddate"]) && $_POST["enddate"] !== "") ? $_POST["enddate"] : date('Y-m-d');
$id = (isset($_POST["id"]) && intval($_POST["id"]) > 0) ? intval($_POST["id"]) : 0;

if($id == 0){
    exit(badRequest(204,'Bad id'));
}else{
    $result = $property->executeByQuerySelector("UPDATE propertyunit SET rented = 'NO' WHERE id = $id");
}
if($result){
	echo success($result,200, "Successful","Successful");
}else{
	exit(badRequest(204,'There may be no record to match this search filters'));
}
?>