<?php
require_once '../config/headers.php';
require_once '../config/database.php';
require_once '../utils/response.php';

if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
    sendResponse(405, 'error', 'Method not allowed');
}

$database = new Database();
$db = $database->getConnection();

try {
    // Join hotel_bookings with hotel_registrations to get the hotel name AND contact details
    $query = "
        SELECT 
            b.*, 
            h.hotel_name,
            h.city,
            h.owner_name AS hotel_owner_name,
            h.owner_contact AS hotel_owner_contact,
            h.property_manager_name AS hotel_manager_name,
            h.property_manager_phone AS hotel_manager_phone
        FROM hotel_bookings b
        LEFT JOIN hotel_registrations h ON b.hotel_id = h.id
        ORDER BY b.created_at DESC
    ";
    
    $stmt = $db->prepare($query);
    $stmt->execute();
    
    $bookings = $stmt->fetchAll(PDO::FETCH_ASSOC);

    sendResponse(200, 'success', 'Hotel bookings fetched successfully', $bookings);

} catch (PDOException $e) {
    sendResponse(500, 'error', 'Database error: ' . $e->getMessage());
}
?>