<?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;

$propertyunits = array();
if($id > 0){
    $resultunits = $property->executeByQuerySelector("SELECT *,(SELECT feename FROM morefees WHERE morefees.id = propertyunit.feenameid) AS feename FROM propertyunit WHERE status LIKE '$status' AND propertyid = $id AND feenameid IN (SELECT id FROM morefees WHERE feename LIKE '%RENT%')");
}else{
    exit(badRequest(204,'Not successful. Property not specified'));
}

if($resultunits){    
	echo success($resultunits,200, "Successful","Successful");
}else{
	echo badRequest(204,'Not successful');
}
?>