<?php
// Required headers
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");

// Include required files
include_once '../config/database.php';
include_once '../objects/room.php'; // Include the Room class instead of RoomType

// Create a database connection
$database = new Database();
$db = $database->getConnection();

// Initialize Room object
$room = new Room($db);

// Get the incoming data
$data = json_decode(file_get_contents("php://input"));

// Set the ID for deletion
$room->id = isset($data->id) ? $data->id : null;

// Attempt to delete the room
if ($room->delete()) {
    echo json_encode(array("message" => "deleted")); // Return a success message in JSON format
} else {
    echo json_encode(array("message" => "error")); // Return an error message in JSON format
}
?>
