<?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"] : "%";
$id = (isset($_POST["id"]) && intval($_POST["id"]) > 0) ? $_POST["id"] : 0;

if($id == 0){
    exit(badRequest(204,'Not successful. We could not find the rented property'));
    //$result = $property->executeByQuerySelector("SELECT * FROM tenants WHERE status LIKE '$status'");
}else{
    $res = $property->getRentAPropertyInfo("id = " . intval($_POST['id']));
    $ref = $res["reference"];
    if($res){
        $result = $property->executeByQuerySelector("DELETE FROM rentedproperty WHERE id = $id");
        $resultaccount = $property->executeByQuerySelector("DELETE FROM accounts WHERE reference = '$ref'");
    }else{
        exit(badRequest(204,'Not successful. We could not find the rented property'));
    }
}
if($result){
	echo success($result,200, "Successful","Successful");
}else{
	echo badRequest(204,'Not successful');
}
?>